I want to get the href attribute to the button click event.
<a v-on:click.prevent="func($event)" href="/user/all/2">
<i class="fa fa-edit"></i>
<span>Get Data</span>
</a>
Main.JS Files
new Vue({
el: 'body',
methods: {
func: function (event) {
element = event.target;
console.log(element); // Output : Select span|i|a element
href = element.getAttribute('href');
},
}
});
Target event does not select a element. It selects the clicked element.
You want event.currentTarget
, not event.target
. Here's a fiddle of the situation: https://jsfiddle.net/crswll/553jtefh/