Ramazan Apaydın Ramazan Apaydın - 1 year ago 331
Javascript Question

VueJS Read Dom Attributes

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>

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.

Answer Source

You want event.currentTarget, not event.target. Here's a fiddle of the situation: https://jsfiddle.net/crswll/553jtefh/

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download