So I want to code a Vanilla Script which changes the style of a text individually. Heres the code of it:
<body>
<p class="black_to_red" onclick="get_red()">If I click this, I am red</p>
<p class="black_to_red" onclick="get_red()">If I click this, I am red</p>
<script>
function get_red() {
text = document.getElementsByClassName("black_to_red");
for (let i = 0; i < text.length; i++) {
text[i].style.color = 'red';
}
}
</script>
</body>
But this code only works kinda. The reason why I say "kinda" is because when I click on a text it changes the style of both textes. Is there a way to make it only effect the specific text I click on it?