Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 449
Thu marlo Avatar asked Jul 27 '11 06:07

Thu marlo


1 Answers

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
    });
like image 148
Marc Uberstein Avatar answered Oct 08 '22 12:10

Marc Uberstein