enter image description here
enter image description hereyour text
enter image description here
Tried to add a class pre-styled when the click action happened.
how to add the line-through style to the element clicked using JavaScript/JQuery?
enter image description here
enter image description hereyour text
enter image description here
Tried to add a class pre-styled when the click action happened.
how to add the line-through style to the element clicked using JavaScript/JQuery?
2
Answers
You can replace e.target with whatever element it is you’re trying to change. Also, if you don’t want to change the styling on repeated clicks, you can simply use addClass or removeClass
If you prefer, here is a non-jQuery solution.
Assuming the elements in question are
<li>
type elements (if they’re not, simply replace the'li'
selector with the one you need):Similarly, as mentioned before, if you only want to add the class and not remove it on subsequent clicks, simply replace the whole
if else
statement withli.classList.add('check');
.