EMM
EMM

Reputation: 181

Get value of custom atrribute in javascript

I have this code

var elem = document.getElementById('EMM');

<span id="EMM" data-var="MM"></span>

Problem is I want to access the value of data-var attribute in elem in JavaScript, something like elem.attributevalue('data-var')

Upvotes: 0

Views: 32

Answers (1)

AmmarCSE
AmmarCSE

Reputation: 30557

Use getAttribute

var elem = document.getElementById('EMM');
alert(elem.getAttribute('data-var'));
<span id="EMM" data-var="MM"></span>

Upvotes: 1

Related Questions