0

Lets say that I have this simple link with data inside:

<a href="#" data-value="Something" onclick="testFunction(this)">X</a>

How can I access this data-value using JavaScript or jQuery.

I tried this but didn't work:

function testFunction(element){
    console.log(element.value);
}

or this

function testFunction(element){
    console.log(element.data('value'));
}

Any help?

harunB10
  • 4,823
  • 15
  • 63
  • 107
  • 1
    Hi Harun, the dataset property is your friend please take a look at this question: https://stackoverflow.com/questions/33760520/get-data-attributes-in-javascript-code – Patrick Hund Sep 27 '18 at 15:02
  • If you want to use jQuery take a look to https://jsfiddle.net/z_acharki/jnwrc5ay/1277/ – Zakaria Acharki Sep 27 '18 at 15:04

0 Answers0