3
var navIcon1 = $('.nav-toggle span, .nav-toggle span:before, .nav-toggle span:after');

if (iconPos >= audPos && iconPos < eventPos) {
  navIcon.css('color', 'black');
  navIcon1.css('color', 'black');

} 

I am trying to change the color of bootstrap navigation. I tried this code but it is not working for me.
Can I change the CSS of pseudo elements with jQuery?

2
  • Did you check by inspecting elements Commented May 28, 2015 at 12:38
  • 5
    pseudo selectors don't work with jQuery Commented May 28, 2015 at 12:38

2 Answers 2

4

Rather than adding css in your if, add a clas to "nav-toggle" for the given position and add your color for that class

Sign up to request clarification or add additional context in comments.

1 Comment

this thing is not working i think i figure it out after 2 hours :)
2

The only one of the elements you can modify using this method is .nav-toggle span, you could do:

if (iconPos >= audPos && iconPos < eventPos) {
  $(".nav-toggle span").css('color', 'black');
} 

As to the other ones: :before, :after etc. are pseudo elements - jQuery can't access them the way you are trying to do it.

Adding a class containing your preferred color to the elements you want to change would be a way of achieving what you want to achieve.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.