jQuery如何获取父母的名字 [英] jquery how to get Name of parent

查看:104
本文介绍了jQuery如何获取父母的名字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

im搜索提供父项名称的元素.这个:

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

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

只是说"DIV",但是我需要一个Element的真实名称.谢谢

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

推荐答案

尝试以下操作(先提示标签名称,然后提示实名):

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

我使用了$(a[0]).attr('name');

例如

$('.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
    });

这篇关于jQuery如何获取父母的名字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆