Alex Rivera | Logout

Getting attribute of a parent node

Asked 2012-02-03T09:19:18.037
18

I am trying to use

$(this).parentNode.attr('data-element')

which should return 0 - 5 in string but it just won't work. I am using it in a function like this

$('.someClass').each(function(){
    $(this).html(SomeFunction('SomeString', $(this).parentNode.attr('data-element')));
});

All the elements with class 'someClass' have a parentNode

<li class="element" data-element: 1 (or any number from 0 to 5 (including))> </li>

and I have no idea where is the mistake. What am I doing wrong?

--David

Edit
Report

1 Answer

3

Using jquery it should be:

$(this).parent().attr('data-element');

Without using jquery this would be:

this.parentNode.getAttribute("data-element")
answered 2012-02-03T09:21:58.287

Your Answer