I have a code like this:
<input required>
In good browsers, I can use jquery as follows to add an error class to the error:
$('input[required]').addClass('error');
However, it does not work in IE. I will resort to it otherwise, but it is not so neat ...
HTML:
<input data-required=true>
JavaScript:
if( $('input').data('required') ) $('input').addClass('error');
Any ideas?
Thanks,
Will
EDIT:
Yes, I use HTML5.
IE really interprets this:
<input required>
as:
<input required="">
So, you can check that like this:
if( $('input').prop() == undefined )
But then again, this is a slightly messy way of doing things, especially considering that this is only IE. This code works great in all other browsers.
I basically ask if there is a validation method that is cross browser and neat. Maybe I'm a little perfectionist !;)
will source share