Shanu Shaji
Shanu Shaji

Reputation: 134

Is it possible to add/remove class property from :before and :after CSS elements?

Is it possible to make jQuery functions (addClass and removeClass) affect :after and :before elements in CSS?

.accordion-heading > a:before {
    background: url(../images/menuleftarrow.png) 98% center no-repeat;
} 
.accordion-heading .accordion-toggle > a:after {
    background: url(../images/menudownarrow.png) 98% center no-repeat;
} 

Upvotes: 0

Views: 144

Answers (1)

Rory McCrossan
Rory McCrossan

Reputation: 337560

It's not directly possible because pseudo elements such as :before and :after do not exist in the DOM.

The workaround is to add or remove the class on the parent element and then use that to key changes in your CSS, something like this:

$('.accordion-toggle a').addClass('foo');
.accordion-heading .accordion-toggle > a.foo:after {
    background: none; /* hide the background */
} 

Upvotes: 3

Related Questions