Joe Half Face
Joe Half Face

Reputation: 2333

Does jQuery work with :before and :after selectors?

For example, I have such line:

$('div#about_title:after').remove();

And it doesn't seem to work, how I can do this?

Upvotes: 2

Views: 151

Answers (3)

PSR
PSR

Reputation: 40338

Try using .next() instead of :after

Upvotes: 0

user2188149
user2188149

Reputation:

You can not use because after you're already taking element by id and id corresponds to only one element then why would not need to put after

$('div#about_title').remove();

Upvotes: 0

jbabey
jbabey

Reputation: 46647

Psuedo-elements created by :before and :after do not technically exist on the DOM, so they can not be manipulated by javascript (and consequently jQuery).

You can edit the CSS to remove them:

<div class="afterStuff"></div>

div.afterStuff:after {
    content: "hi";
}

$('.afterStuff').removeClass('afterStuff');

I would recommend adding/removing classes over directly modifying inline styling.

http://jsfiddle.net/UUPks/

Upvotes: 2

Related Questions