0

I've spotted a number of posts stating that I can't manipulate a Pseudo Element with jQuery so I'm looking for a workaround?

I'm looking to run a a/b split test in Optimizely on our site search bar. The design of the current search bar has css that creates the search icon using the ::before Pseudo element to place a glyph-icon as a button to start the search.

As my test I wanted to change the colour of this icon. Optimizely allows you to use jQuery to target elements and make these types of changes.

The current css looks like this:

.header .form-search button:before, .header .form-search .search- button:before {
content: "\f002";
font-family: "polar-icons";
color: #237cb2;
font-size: 1.8rem;
}

This was the jQuery I was attempting to implement but it didn't work:

$(".search-button::before").css({'color':'#E93826'});

Any help greatly appreciated.

4
  • Why don't you just toggle a class? Because you cannot target pseudo elements using js/jquery .search- button:before.sexyClass {color: #E93826; } Commented Jul 27, 2015 at 13:11
  • stackoverflow.com/questions/5041494/… Commented Jul 27, 2015 at 13:13
  • @SrinivasPai OP doesn't want to change content but style Commented Jul 27, 2015 at 13:14
  • Sorry, it should be: .search-button.sexyClass:before {color: #E93826; } Commented Jul 27, 2015 at 13:19

1 Answer 1

1

Try:

$('head').append('<style>.search-button::before{color:#E93826 !important}</style>');
Sign up to request clarification or add additional context in comments.

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.