0

Is it possible to target a css classname:after via jquery to alter a style dynamically?

I have a css arrow in a slider - i'd like to change color based on percentage complete - at the moment I have -

 $('.red-bar:after').css("background-color", "#1da9f5");

Which doesnt work! any ideas?

Dancer
  • 17,035
  • 38
  • 129
  • 206

1 Answers1

2

You'll want to use the .next() function:

http://api.jquery.com/next/

$('.red-bar').next().css("background-color", "#1da9f5");

More info: .next() gets the next sibling of the selected item. If you want to add new content after the selected item, use .after().

Example:

<div id="my_id"></div>
<div id="ignore_me></div>

Now, if you call: $("#my_id").next().html("Hello");, you'll get:

<div id="my_id"></div>
<div id="ignore_me>Hello</div>

But if you call $("#my_id").after("Hello");, you'll get:

<div id="my_id"></div>
Hello
<div id="ignore_me></div>
Flater
  • 12,908
  • 4
  • 39
  • 62