In the code below, I have four elements. When a specific element is clicked, I would like for it to change color. Right now, for some reason, the entire row of elements is changing color, and not the individual element. Here is my code:
<style>
.tag14 span {
padding: 6px 10px;
background: brown;
border-radius: 20px;
color: #091747;
font-family: Roboto;
font-size: 14px;
margin: 0 4px 8px 0;
font-weight: 500;
display: inline-block;
word-wrap: break-word;
white-space: normal;
cursor: pointer;
}
}
.tag14 span:focus{
background:green;
}
</style>
<script>
function myfunction(elmt)
{
elmt.style.backgroundColor = "blue";
}
</script>
<div class="tag14" onclick="myfunction(this);">
<span class="tag_span">
Hello
</span>
<span class="tag_span">
Hi
</span>
<span class="tag_span">
Hello
</span>
<span class="tag_span">
Hi
</span>
<span class="tag_span">
Hello
</span>
</div>
I suspect it has to do with how my class is named and the parameter of the onclick function.
on*
handlers same as you hopefully don’t use inlinestyle
attributes. JavaScript should be in one place only – and that’s yourscript
.Use Element.addEventListener() instead with Event.currentTarget
myfunction
– cause it means nothing to nobody. name your function exactly as a short describer of the job it does or the value it returns.Here you go:
If you give specified class name to all four elements then you can select one element and then you can change that specific elements color
*The one who downgraded my comment please point out the mistake
Thank You
tadalafil vs sildenafil – tadalafil cost tadalafil canadian pharmacy
stop taking propecia for 10 days – missed propecia dose buy genuine propecia
finasteride reddit – http://propechl.com/ what is propecia used for
liquid tadalafil – http://xtadalafilp.com/ tadalafil 20 mg