Make a single css character in website style?

The client asked only / his site to be red ... Throughout the entire site!

Do I need to add spaces around each /, or is there an easier way?

+4
source share
4 answers

Hope this sample helps. I found it in SO. You can replace ® to html slash /

 $(document).ready(function() { $('*').each(function() { var n = $(this).html().replace( new RegExp('®','g'), '<sup>®</sup>' ).replace( new RegExp('&reg;','g'), '<sup>&reg;</sup>' ); $(this).html(n); }); });​ 

Demo

+3
source

You can try to execute jQuery script:

 $('body').html($('body').html() .replace(/\/(?=[^>]*<)/gi, '<span style="color:red">/</span>'));​​​​ 

It simply wraps all slashes that are not inside tags with an interval.

Check how quickly this happens for your site, I believe that it can be useful.

Here is FIDDLE to demonstrate that using lookahead (?=[^>]*<) Is important to prevent matches within the <> tags for replacement, try removing it, and the resulting HTML will break.

+2
source

Unable to execute only css. Check link how to do it with javascript

0
source

You must wrap each occurrence of a character within span markup or other suitable markup. (Actually, <font color=red>/</font> will work as well.) However, you can do this dynamically on the client side if it sounds more appropriate (you will have client-side JavaScript that moves through the document tree and performs transfer).

Note. This does not apply to content in elements that have plain text in the declared form, for example option . Inside them, individual characters cannot be written otherwise than other elements of the element.

-1
source

Source: https://habr.com/ru/post/1441528/


All Articles