Tôi đang cố gắng lấy tên thẻ phần tử trong jQuery.Tên thẻ jQuery của phần tử
Tôi có html sau:
<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>
Và javascript:
$(".edit").click(function(){
$(this).closest("div.section").children().each(function(){
alert($(this).tagName + " - " + $(this).html());
});
})
Tôi đã thử $(this).tagName
, $(this).nodeName
và $(this).attr("tag")
như đã nêu trong câu hỏi này: Can jQuery provide the tag name?
Nhưng tôi m luôn nhận được undefined
đổi lại. Đầu ra html()
chính xác. Tại sao tôi không thể lấy tên thẻ của từng phần tử?
có thể trùng lặp của [jQuery: Nhận phần được chọn tên thẻ] (http://stackoverflow.com/questions/5347357/ jquery-get-selected-element-tag-name) – Druzion