Suppose I a complete sentence when I click on any of the words I was trying to highlight that word and read the value into a javascript variable.
If I click on the three words then all three words should be highlighted by green color and store the value as a string in a variable.
<p onclick="handleClicks()" class="word" >
Select the choice words that make up the complete sentence.
</p>
Now if I click on Select
, words
and complete
then it should be highlighted and all the selected values should be saved inside a variable in javascript.
Is it possible to do so using javascript?
What I tried is
const handlClicks = (event) => {
const clickedElem = event.target
clickedElem.classList.toggle('active');
}
But this does not work. should I use multiple span tag inside of the p tag and then apply a function to all the span