Are you aware of <button>
elements? <button>
elements can be styled just like <div>
elements and can have type="submit"
so they submit the form without javascript:
<form action="whatever.html" method="post">
<button name="mysubmitbutton" id="mysubmitbutton" type="submit" class="customButton">
Button Text
</button>
</form>
Using a <button>
is also more semantic, whereas <div>
is very generic. You get the following benefits for free:
<button type="submit">
becomes a "default" button, which means the return key will automatically submit the form. You can't do this with a <div>
, you'd have to add a separate keydown handler to the <form>
element.There's one (non-) caveat: a <button>
can only have phrasing content, though it's unlikely anyone would need any other type of content when using the element to submit a form.