change color of replaceAll comma with arrow

Viewed 33

I have used replaceAll function which is perfectly working - I want to change the color of arrows. How can I do that? Please help I am a beginner.

Here is my jQuery code

let network = '';
if ($('#depsTo').val()) {
    network = $('#depsTo').val();
    network = network.toString().replaceAll(',','--->');
    console.log("NETWORK : " + network);
    $('#networkHeading').html(network);
}
2 Answers

Just use html! You could use span, as I have in this snippet:

let network = 'This, is, a, test, string';
  network = network.toString().replaceAll(',','<span style="color:red">---></span>');
$('#networkHeading').html(network);
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div id="networkHeading"></div>

If you want same color again and again then use this

$('#' + id).css({"color":"blue"});

And if you want different color every time then use this in for loop

 var r = Math.random() * 256
 var g = Math.random() * 256
 var b = Math.random() * 256

$('#' + id).css({"color":`"rgba(${r},${g},${b},${a})"`});
Related