Why do people use buttons and other HTML inputs?

With the exception of the text input field, I cannot understand why anyone wants to use HTML input.

This is a nightmare trying to style them in all browsers, and it’s much easier to create a normal div as a button and then use the jquery onClick function.

Like this: JSFIDDLE

$('.clickme').hover(function() { $(this).animate({"color":"#e8a010","font-size":"52pt"}, 1000); }, function() { $(this).animate({"color":"#fff","font-size":"13px"}, 1000); }); 

Why do people use buttons and then try to style them when they can just style the div? Is there any advantage? Did I miss something?

+4
source share
2 answers

Availability mostly. button and input elements can be set by focus using Tab , and then interact using the keyboard. A div created as a button will never get focus through tabs.

Although this behavior cannot be reproduced using elements other than the form, you receive them for free.

+10
source

There is availability and wider compatibility. What happens if you have javascript disabled? your "button" does nothing, while the function of the native button still works

+3
source

Source: https://habr.com/ru/post/1497424/


All Articles