+ 2
What's wrong with this javascript?
3 Réponses
+ 1
regex only matches the word from paragraphs inner text, it doesn't append p to the result.
What you are trying to do is this(after line 5)
for(var I=0; I<p.length; I++)
if(p[I] == 'barrage')
p[I].style.color = 'red';
+ 1
If I could understand your code correctly, is you want to find all the matched word "barrage', set them in red color.
Here the code you could try
document.addEventListener('DOMContentLoaded', function(){
var p = document.getElementById("text");
var t = p.innerText;
p.innerHTML = t.replace(/barrage/gi, '<span style="color:red">amp;</span>');
});
https://code.sololearn.com/W4znvcTzy9Yt/?ref=app
+ 1
How does amp; work