JSFiddle - React, Tailwind, and code Playground
by kasperfish
HTML
<pre class="code">
//I need to color this line
Some code
//This line should also be colored
More code
</pre>
CSS
span{
color:blue;
display:block;
}
JavaScript
var lines = $('pre.code').text().split('\n');
var formatted="";
$.each(lines, function(){
if(this.trim().substring(0, 2)=='//'){
formatted+='<span>'+this+'</span>';
}
else{
formatted+=this;
}
});
$('pre.code').html(formatted);