1

I am wanting to change the color of the stars on this page using js edit:link is now dead

It is the :before on the class "star-rating" that is controlling the color but I have not been able to successfully change it, possibly because it has an important on it.

I read this but it didn't help Javascript set CSS :after styles

Thanks

Alex

4
  • why you need js? it can be done only with css Commented Dec 5, 2013 at 14:03
  • I only want it to happen on certain pages, and I didn't make the theme so would rather stay out of the css files Commented Dec 5, 2013 at 14:04
  • so you can create your own stylesheet or put it on the head of the pages you want are you searching a solution for pure js or jquery too? Commented Dec 5, 2013 at 14:05
  • the pages are dynamically created by a plugin in Wordpress, js is the only way I can achieve what I want to do Commented Dec 5, 2013 at 14:07

2 Answers 2

1

Probably not the nicest way to do it, but

s = document.createElement('style') ; 
s.innerHTML = '.star-rating span:before, .star-rating:before, .woocommerce-page .star-rating:before { color:pink !important}' ; 
document.head.appendChild(s); 

i.e. add a style tag to the head which overrides the style for those stars.

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

Comments

0

The only solution is to remove and add new DOM for that stars or you can remove that !important from css and then change by using JS.

Otherwise use jquery and then :

starDiv = document.getElementsByClassName("star-rating")[0];
$(starDiv).css('color', 'red', 'important');

1 Comment

You can do that by using jquery but you are not using jquery

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.