Iladarsda Iladarsda - 1 year ago 105
Javascript Question

AngularJS - get element attributes values

How do you get an element attribute value?

HTML element:

<button data-id="345" ng-click="doStuff($">Button</button>


function doStuff(item){
angular.element(item)[0].data('id'); // undefined is not a function

Any suggestions much appreciated,
JSFIDDLE demo here:

rob rob
Answer Source

Since you are sending the target element to your function, you could do this to get the id:

function doStuff(item){
    var id = item.attributes['data-id'].value; // 345
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download