开发者

jQuery - find class of radio element for validation

开发者 https://www.devze.com 2023-02-21 06:45 出处:网络
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 :

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");
0

精彩评论

暂无评论...
验证码 换一张
取 消