【发布时间】:2013-04-06 00:37:24
【问题描述】:
我正在尝试在 jQuery 中获取元素标签名称。
我有以下html:
<div class="section" id="New_Revision">
<h1>New Revision <img alt="Lock_closed" class="edit" data-id="1" src="/assets/lock_closed.svg" /></h1>
<p>This is a test paragraph.</p>
<ol class="references">
<li>test</li>
</ol>
</div>
还有 javascript:
$(".edit").click(function(){
$(this).closest("div.section").children().each(function(){
alert($(this).tagName + " - " + $(this).html());
});
})
我已经尝试过 $(this).tagName、$(this).nodeName 和 $(this).attr("tag"),如本问题所述:Can jQuery provide the tag name?
但我总是得到undefined 作为回报。 html() 输出正确。为什么获取不到每个元素的标签名?
【问题讨论】: