开发者

jQuery add checked="checked" to radio/checkboxes

So, I have a CSS style defined for a radio/checkbox when it has the checked="checked" value

input[type=radio][checked=checked] {
  /* CSS */
}

This works great whenever a fresh page is loaded, but when a radio/checkbox is toggled on the page, the DOM never adds checked="checked" to that HTML tag... Therefore, my CSS doesn't work.

I tried using jQuery to add the checked="checked" attribute, but that only checks/selects the radio/checkbox, it doesn't actually add the checked="checked" attribute.

Can I change my CSS selector/do something with jQuery to fix this!? It's driving me insane. I conside开发者_开发技巧r myself a fairly skilled coder with CSS and jQuery and this is a rather trivial matter, but I just can't wrap my head around it.


Okay, well for anyone else who has this problem...

Instead of using [checked=checked] in the CSS, I tried :checked (CSS3 selector) and it works. Although I'm not sure it's supported in earlier browsers

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜