I have multiple list items that I want to toggle active classes on when they are being clicked on.
-
You can directly pass the event and the events target in your function. The target is the element you clicked on.
HTML:
- Trigger a handler
- Trigger an expression
JS:
var vue = new Vue({
el: '#demo',
data: {},
methods: {
onClick: function (e) {
var clickedElement = e.target;
}
}
})
With your element you can do what you want. For example, if you use jQuery:
$(clickedElement).siblings().removeClass('active');
$(clickedElement).addClass('active');