0

I'm trying to change the background color of a radio button with jQuery. I posted the css below, but in jQuery I need to escape the special characters (see below) and its still not working.

#opt5 > [type="radio"]:not(:checked) + label:before,
#opt5 > [type="radio"]:checked + label:before {
    background: #F7DC6F;
}

$("\\#opt6 \\> \\[type\\=\\'radio\\'\\]\\:not\\(\\:checked\\) \\+ label\\:before").css({ "background": "red" });
$("\\#opt6 \\> \\[type\\=\\'radio\\'\\]\\:checked \\+ label\\:before").css({ "background": "red" });
SAS20
  • 49
  • 8
  • 3
    jQuery doesn't support pesudo elements AFAIK – Aziz Aug 19 '16 at 17:34
  • 2
    why do you want to escape the special characters??? `$('#opt5 > [type="radio"]:not(:checked) + label')` is a complete fine statement and yes as @Aziz said, you cannot access pseudo elements – empiric Aug 19 '16 at 17:34

1 Answers1

0

This has nothing to do with the selector syntax. jQuery's selector engine is designed to support CSS selectors out of the box (to some extent, anyway). By escaping it you're stripping the selector of all its meaning turning it into something completely different from what you expect.

This has everything to do with the fact that pseudo-elements cannot be selected by jQuery. You have a number of options, which are covered in the link. I highly recommend the class name approach.

Community
  • 1
  • 1
BoltClock
  • 700,868
  • 160
  • 1,392
  • 1,356