7th Dec 2018, 12:48 AM
Jeremy Cruz
Jeremy Cruz - avatar
3 Antworten
+ 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';
7th Dec 2018, 3:04 AM
‎ ‏‏‎Anonymous Guy
+ 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
7th Dec 2018, 7:12 AM
Calviղ
Calviղ - avatar
+ 1
How does
amp; work
7th Dec 2018, 10:48 AM
Jeremy Cruz
Jeremy Cruz - avatar