The style of a particular letter?

I would like to write letters based on what the letter is. So K: s sholud has one color, I: s one, etc. What is the cleanest way to do this? Is there a selector for this? (initially I am going to do this with greasemonkeyscript)

+4
source share
3 answers

Javascript, untested fixed:

yourstring.replace(/([kK])/g, "<span class='styled'>$1</span>"); 

Working example:

 <html><head></head><body> <div id='target'> some text with little ks and big Ks and a few more for good measure kK7k9Kii </div> </body></html> <script type='text/javascript'> target = document.getElementById('target'); target.innerHTML = target.innerHTML.replace(/([kK])/g, "<span style='color:red'>$1</span>"); </script> 

MDN .replace() documentation here .

+5
source

You can also use the lettering.js plugin.

0
source

You can do this with jquery very easily, as shown below:

Html:

 <p class="menu">Home k edit k etc</p> 

Css:

 span.sp { font-weight: bold; color: red; } 

Javascript / Jquery:

 $('p.menu').html(function(i,el) { return el.replace(/\k/g, '<span class="sp">k</span>'); }); 

Here is the jsFiddle Link

0
source

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


All Articles