Dynamically changing background color of specific text without changing other attributes

Posted by gsingh2011 on Stack Overflow See other posts from Stack Overflow or by gsingh2011
Published on 2013-07-01T22:54:42Z Indexed on 2013/07/01 23:05 UTC
Read the original article Hit count: 253

Filed under:
|
|
|

I've written a chrome extension to find text on a page based on a regex query. When text is matched, I wrap the matched text in a <span> tag that has the class highlight where highlight only changes the background color to yellow.

The issue is that sometimes there are already styles applied to <span> tags in a webpage. For example, the webpage might have this defined:

span {
  font-size: 200%;
}

So when I insert my <span> tag in another <span> tag, the font-size is actually 400%.

Is there an easy way for my code to just change certain properties of the text, like the background color, without applying the webpage's styles twice?

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about html