Thu marlo Thu marlo - 4 months ago 10
jQuery Question

jquery how to get Name of parent

im searching for the Element whicht Provides the Name of a Parent. This:

$('.Item').click(function(){
var a = $(this).parent();
alert(a[0].tagName);
});


just says "DIV", but I need the real name of a Element. Thanks

Answer

Try the following (Alerts the tag name, and then the Real Name) :

I used $(a[0]).attr('name');

e.g.

$('.Item').click(function() {
        var a = $(this).parent();
        alert(a[0].nodeName.toLowerCase()); //Tag Name

        alert($(a[0]).attr('name')); //Attribute (real) name
        //OR
        alert(a.attr('name')); //Attribute (real) name
    });