Vuejs getting the element that is being called by an event? Vuejs getting the element that is being called by an event? vue.js vue.js

Vuejs getting the element that is being called by an event?


You can directly pass the event and the events target in your function.The target is the element you clicked on.

HTML:

<ul id="demo">    <li v-on="click: onClick">Trigger a handler</li>    <li v-on="click: n++">Trigger an expression</li></ul>

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');