0

Possible Duplicate:
Manipulating CSS :before and :after pseudo-elements using jQuery

So i have a click event and after it has been clicked i want to target the pseudo element after.

    $('.expanable h3').click(function(){
        $(this).....TARGET AFTER
    });

I would like to change the styles of the :after

Community
  • 1
  • 1
Jamie Hutber
  • 26,790
  • 46
  • 179
  • 291
  • 3
    I think your best bet is to add/remove something from the "class", and have different CSS with and without that (and :after of course). – Pointy Jul 17 '12 at 14:23
  • @boltClock i wouldn't say its a duplicate as i'm trying to target with $(this) not just in general./ pointy this is what i was going to do, but i didn't really want this approach. david i didn't know this. Thanks – Jamie Hutber Jul 17 '12 at 14:25
  • I think it's a duplicate since the essence of the problem is manipulating `:after` and the rest is irrelevant noise – Esailija Jul 17 '12 at 14:27
  • ye.. ok I'll agree with that :) The underlining problem is the :after rather than the this part. – Jamie Hutber Jul 17 '12 at 14:29
  • If you want the next element, you could use $(this).next(). Would that help you? – Angel Jul 17 '12 at 14:29
  • although Esailija, i do feel it would help people thinking the same way as i am. On that basis it'd be educational. – Jamie Hutber Jul 17 '12 at 14:32
  • @Pointy: You'll want to post that as an answer. – BoltClock Jul 17 '12 at 14:49
  • @BoltClock: that "duplicate" link is *fantastic*! – Oleg Jul 18 '12 at 04:26

1 Answers1

1

You can set up rules like this:

h3:after { content: "."; }

h3.emergency:after { content: "!"; }

Then adding or removing the class "emergency" will change the ending of the <h3> text to be either "." or "!".

There's the attr() mechanism in CSS that allows attributes of affected elements to serve as content, but I'm not sure that's well-supported enough to rely on.

Pointy
  • 405,095
  • 59
  • 585
  • 614
  • :) i went with just adding and removing a class which had the rules set inside my styles. I just wanted a more elegant option. Cheers all the same – Jamie Hutber Jul 17 '12 at 15:23