+ 3

What is the difference between these two kind of button?

https://code.sololearn.com/We6BX2eAATN2/?ref=app

31st Aug 2019, 5:50 AM
Adi Pratama
Adi Pratama - avatar
7 Réponses
+ 10
The differences are subtle. 1. <button> is easier to style with other tags like <em> or <strong> as nested elements. 2. <button type="submit" /> is a newer alternative to <input type="submit" />. 3. If button is the only button within a form tag, it will automatically become the submit button and post the form upon the click event. This can be avoided by explicitly setting the type to "button". Here are some good links to read for additional differences: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/button#Notes https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/submit
31st Aug 2019, 7:32 AM
David Carroll
David Carroll - avatar
+ 6
Matheus Rodrigues You can use either button for either scenario. I think you might be reflecting what appears to be common usages for these buttons.
31st Aug 2019, 2:54 PM
David Carroll
David Carroll - avatar
+ 4
Calviղ w3schools still show there's a button attribute 'type', is that because they haven't updated the page? https://www.w3schools.com/tags/att_button_type.asp
31st Aug 2019, 7:06 AM
Ipang
+ 3
Use input type="submit" for form submission, pressing the submit button would trigger onsubmit event of the form element. It can also used for submitting form to server from form attributes action and method.
31st Aug 2019, 6:12 AM
Calviղ
Calviղ - avatar
+ 2
Button does not have attribute type <button type="submit">Submit</button> is a wrong syntax. button would response with onclick attribute usually.
31st Aug 2019, 6:16 AM
Calviղ
Calviղ - avatar
+ 2
the type button is better to use to some animation or interation that you want for the user. The type submit send a request to url. It’s better to use to send data.
31st Aug 2019, 2:51 PM
Matheus Rodrigues
Matheus Rodrigues - avatar