jQuery - find class of radio element for validation
I need to target all radio elements with the class of 'error' and change the colour of the surrounding 'td' element, this is not working for me :
$(':radio').hasClass('error').closest("td").css("bac开发者_如何学编程kground", "#FBDDDD");
or
$(':radio.error').closest("td").css("background", "#FBDDDD");
is there some other way of checking a radio/checkbox elements class?
Use parent function
$(this).parents("td:first");
Here you go http://jsfiddle.net/kH7NN/2/
This will work:
$("input:radio.error").closest("td").css("background-color", "#FBDDDD");
精彩评论