Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

<input type=button> vs <button> [duplicate]

Tags:

html

dom

I'm a little confused. What is the difference between these. Please don't reference really old postings. I notice that accessing some of the styles are different inline in html as well as in style sheets.

<input type=button>     vs  <button> 

I guess I'm wondering which one will out live which? or which is the best when taking into account ease of compatibility between all the general technologies that go into website creation? aka. which is going to cause the least amount of trouble

like image 415
Strawberry Farmer Avatar asked Aug 21 '14 21:08

Strawberry Farmer


People also ask

Should I use input type button or button?

The difference is that <button> can have content, whereas <input> cannot (it is a null element). While the button-text of an <input> can be specified, you cannot add markup to the text or insert a picture.

What is the difference between input type and button type?

A 'button' is just that, a button, to which you can add additional functionality using Javascript. A 'submit' input type has the default functionality of submitting the form it's placed in (though, of course, you can still add additional functionality using Javascript).

What is input type button?

Definition and Usage. The <input type="button"> defines a clickable button (mostly used with a JavaScript to activate a script).

What is the difference of regular HTML button and submit button?

submit: The button submits the form data to the server. This is the default if the attribute is not specified, or if the attribute is dynamically changed to an empty or invalid value. reset: The button resets all the controls to their initial values. button: The button has no default behavior.


2 Answers

Unlike <input> tags, <button>'s can contain other html elements as their labels. <input type="button"> can only accept a string as its label text (css styles not withstanding).

Additionally, the <button> element accepts a wide range of uncommon but useful attributes regarding multiple forms and click actions. See the MDN page for more details.

As for one "out living" the other, the HTML standard is remarkably backwards compatible. Humanity will put men on Mars before either is eliminated from the HTML standard.

like image 172
Ben Roux Avatar answered Sep 22 '22 03:09

Ben Roux


Inside a <button> element you can put content, like text or images. eg: <button type="button" onclick="alert('Hello world!')">Click Me!</button>

If you use the <button> element in an HTML form, different browsers may submit different values. So always use <input type="button"> to create buttons in an HTML form.

like image 26
Jijin M Avatar answered Sep 22 '22 03:09

Jijin M