Take the 2-minute tour ×

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

If I have an element, how do I address its corresponding pseudo element using jQuery?

My point is, for example if I have an element in the DOM, how do I access its :before or :after pseudo elements with jQuery?

P.S. I only have a jQuery pointer to that element.

share|improve this question

marked as duplicate by Vohuman, arttronics, Travis J, false, François Wahl Jan 2 '13 at 9:34


You can't, what are you trying to achieve? –  Musa Jan 2 '13 at 1:04
There should be a way. I need to add a background to the pseudo element. –  Itay Grudev Jan 2 '13 at 1:18
@undefined It may be a duplicate indeed. I'll review it and delete the question myself if it is so. –  Itay Grudev Jan 2 '13 at 1:18
I guess that it is really impossible. I looked at the solution of the original question and and I can't adapt it either (stackoverflow.com/questions/9244197/…). –  Itay Grudev Jan 2 '13 at 1:57

1 Answer 1

Perhaps your looking to create an element that simply doesn't exist. Use jQuery .after() to create it. (Likewise, you can use jQuery .before() too!)

<div id="element">123</div>
#element {
 float: left;
 color: white;

.selected {
  width: 100px;
  height: 100px;
$('#element').after('<div class="selected"></div>');

jsFiddle DEMO

jsFiddle DEMO with Remove

share|improve this answer
+1 for the solution, but I can't really modify the DOM. –  Itay Grudev Jan 2 '13 at 1:56
Please clarify "I need to add a background" in your comments. Thanks. –  arttronics Jan 2 '13 at 1:59
