My company is building a website and we had some problems with a JavaScript library not replacing something. We decided to throw our HTML in to the W3C validator and it informed us it's illegal to have a <div>
tag inside a <button>
tag.
<button class="button" type="submit">
<div class="buttonNormalLargeLeft"><!--#--></div>
<div class="buttonNormalLargeCenter">Search Flights</div>
<div class="buttonNormalLargeRight"><!--#--></div>
</button>
Results in:
Line 287, Column 46: Element div not allowed as child of element button in this context. (Suppressing further errors from this subtree.)
Edit: To clarify what we're trying to do here. We want to make a button with rounded corners that doesn't rely on box-radius
. We made 3 divs in the button element each has his own sprite to make it appear rounded and allow for different widths. Other resources state that the button element was created for users that wanted a button to contain sub elements such as images but divs appear to be invalid for some reason.
Why are divs not allowed inside button elements?
What is the desired solution to this issue?
Edit2:
Why not use input? Because inputs can't have the desired layout
Why not use divs? Because users without JavaScript won't be able to submit the form.
<button>
IMHO), but it just doesn't validate. I would say if it works, leave it – Pollsterdiv
for the button, display & submit with JS, then use a standard button in<noscript>
tags for those without JS... Or, as others have suggested, just ignore validation because it seems to work in-browser even though it's against spec. – Jellicoe<img />
tag inside yourbutton
? Validates and you get to create your button with rounded edges withoutbox-radius
and will work on any browser. – Vigorous