(Not a big fan of speaking to myself....
:sob:)
I wrote this NEAT little single-line function built from a couple of stackoverflow inspirations, that turns inputs into buttons.
$(function () {
$('input[type=button],input[type=submit],input[type=reset]').each(function () {
$(this).replaceWith($((this.outerHTML || new XMLSerializer().serializeToString(this)).replace(/^<input/, '<button')).html(this.value));
});
});Inputs are cool, because their HTML is shorter. But:
- They don't accept :before and :after, because it's "semantically" frowned upon as they have no proper 'content'... Bollocks!
- Because of that, I can't add an extra 3D border without resorting to using multiple backgrounds...
- And multiple backgrounds are only supported by IE9+, so bye bye other IEs. Not that it matters much...
- Also, with my recent rewrite to make it, err, cross-browser pixel-perfect (which I still haven't achieved), I need to re-specify my entire list of backgrounds every time. Thankfully, gzip will notice that and limit the catastrophe to just a few lost bytes. Still, it looks ugly in the code... Perhaps also because I'm forced to generate strange CSS variables for IE at the end of the file.
Buttons are cool (except for the extra size) because:
- you can put straight HTML into the contents, duh!
- they accept :before and :after, AFAIK, and anyway it's easier to generate content around them,
- :before and :after are supported in IE7 and IE8,
- so I can add my extra borders to these pseudo-elements, and fix the problems mentioned above...
- and I supposedly can more easily style the entire thing across browsers. However this isn't the case in practice -- I noticed Firefox has the exact same behavior as with inputs. Uh...
So. What do you think is best?
And if <button> is best -- I suppose I should do a site-wide replace, shouldn't I...? Well, easier said than done. I have a feeling that I'll have to do it all manually... 1500+ occurrences and probably many jQuery tests for 'input' tags
:-/ And the function above will, as always, give a noticeable delay before it's all transformed.