2

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.

Community
  • 1
  • 1
Itay Grudev
  • 7,055
  • 4
  • 54
  • 86
  • You can't, what are you trying to achieve? – Musa Jan 02 '13 at 01:04
  • There should be a way. I need to add a background to the pseudo element. – Itay Grudev Jan 02 '13 at 01:18
  • @undefined It may be a duplicate indeed. I'll review it and delete the question myself if it is so. – Itay Grudev Jan 02 '13 at 01: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 (http://stackoverflow.com/questions/9244197/css-content-attr-and-url-in-the-same-sentence). – Itay Grudev Jan 02 '13 at 01:57

1 Answers1

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 {
  background-image:url("http://www.gravatar.com/avatar/bb7148ce65e69d732186e93116462cb2?s=100&d=identicon&r=PG");
  width: 100px;
  height: 100px;
}
$('#element').after('<div class="selected"></div>');

jsFiddle DEMO

jsFiddle DEMO with Remove

arttronics
  • 9,957
  • 2
  • 26
  • 62