javascript - Vue.js - Add Class on Click Event -
i dynamically toggle class on click
event on div in vue.js without using properties/data so.
here div
<div class="quiz-item" @click="checkanswer(1)">
when div
clicked, add class quiz-item--correct
or quiz-item--incorrect
(the logic handled elsewhere). cannot use properties there many answers in quiz maintainable/viable approach.
does have ideas on how can achieve functionality?
you can this:
<div class="quiz-item" @click="$event.target.classlist.toggle('classname')">
you can check fiddle demonstrating this: here
Comments
Post a Comment