VueJS Read Dom Attributes

Ramazan APAYDIN picture Ramazan APAYDIN · Sep 6, 2016 · Viewed 28.9k times · Source

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.

Answer

Bill Criswell picture Bill Criswell · Sep 6, 2016

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