Update CSS of Pseudo Element with jQuery

bbacarat

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.

Fernando Molina

Try:

$('head').append('<style>.search-button::before{color:#E93826 !important}</style>');

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to dynamically alter the CSS of a pseudo element with JQuery?

From Dev

Modify the css of a pseudo element using JQuery

From Dev

CSS pseudo element not working

From Dev

CSS Overlay with pseudo element

From Dev

CSS pseudo element blockquote

From Dev

Pseudo element content with JQuery

From Dev

Modify CSS of the :after pseudo-element using jQuery

From Dev

Modify CSS of the :after pseudo-element using jQuery

From Dev

add css to a pseudo element of jQuery object that already stored in variable

From Dev

CSS pseudo element transform is choppy

From Dev

CSS Pseudo Element Full Height

From Dev

Rounded corner with pseudo element css

From Dev

How to rotate pseudo element css

From Dev

CSS pseudo element transform is choppy

From Dev

CSS " :: " vs " : " -- pseudo-element vs pseudo-selector?

From Dev

Select the first CSS element using a pseudo class

From Java

IE crossing out pseudo element CSS?

From Dev

CSS, using display:table with before pseudo element

From Dev

Insert &times; using CSS pseudo element

From Dev

CSS Transition on the 'content' property of :before pseudo element

From Dev

CSS3 Columns and pseudo element positioning

From Dev

CSS :first-child pseudo-element

From Dev

LESS CSS selector combining not and :after pseudo element

From Dev

Creating a shape using a :before pseudo element in CSS

From Dev

How to set css attribute for pseudo element in Dart

From Dev

CSS Mix-Blend-Mode on pseudo element

From Dev

CSS - Using a pseudo-element for an image mask

From Dev

css3: Transform animation for pseudo element

From Dev

CSS Transition on the 'content' property of :before pseudo element

Related Related

HotTag

Archive