So I have this HTML element that adds/logs some paragraphs to it.
Here is an example of the HTML
:
<div id="team_log_actual" class="log"> <p><b>[<span style="color: #0FF">Captain</span>] <span style="color: #0FF;">☘️B☘NK☘️</span><100001177></b> is using station: Helm (Starter).</p> <p><b> <span style="color: #FFF;">RegularHacker</span><1322></b> unloaded an RC turret.</p> <p><b> <span style="color: #FFF;">RegularHacker</span><1322></b> is using station: Fabricator (Munitions).</p> <p><b>[<span style="color: #0FF">Captain</span>] <span style="color: #0FF;">☘️B☘NK☘️</span><100001177></b> is using station: Helm (Starter).</p> <p><b> <span style="color: #FFF;">RegularHacker</span><1322></b> is using station: Fabricator (Munitions).</p> <p><b>[<span style="color: #0FF">Captain</span>] <span style="color: #0FF;">☘️B☘NK☘️</span><100001177></b> is using station: Fabricator (Munitions).</p> </div>
In that HTML you can see "is using station: Fabricator (Munitions)" inside one of those paragraphs.
So if a paragraph with that text gets created(logged) in that DIV with the class "log"
. Change that paragraph's style. Like this:
Original:
<p><b>[<span style="color: #0FF">Captain</span>] <span style="color: #0FF;">☘️B☘NK☘️</span><100001177></b> is using station: Fabricator (Munitions).</p>
Change into:
<p><b>[<span style="color: #00FF00">Captain</span>] <span style="color: #0FF;">☘️B☘NK☘️</span><100001177></b> is using station: Fabricator (Munitions).</p>
Changes the first span's color...
I have no idea how to do such a thing. Possibly using innerHTML
?
Add an id to your html like:
<p id="span"><b>[<span style="color: #0FF">Captain</span>] <span
style="color: #0FF;">☘️B☘NK☘️</span><100001177></b>
and in you js file write:
Let span=getElementById="span";
Span.addEventListener("click",function(){
Span.style.color="red or any wanted color"
})
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.