0

I wrote a javascript by taking support from the Internet to color specific characters ("a" and "0") within some HTML text.

It's working with getElementById but I need to apply it to several places in same page, So I tried by using "getElementsByClassName" but it didn't work.

<script>
window.onload= function (){
var s1 = document.getElementsByClassName("redphrase");
var str = s1.innerHTML; var newText = "";
for (var i = 0; i < str.length; i++) {if((str[i] == '0' || str[i] == 'a')) {newText+= str.charAt(i).fontcolor("red");
}
else
{ newText += str[i];
}
}
s1.innerHTML = newText;
}
</script>

<a href="#" class="redphrase"><b>Here are somE words 00</b></a>

<a href="#" class="redphrase"><b>Here are somE words 00</b></a>

I expect the output to apply color red into characters "a" and "0" in both lines, but it doesn't work.

0 Answers0