Próbuję uzyskać nazwę znacznika elementów w jQuery.Nazwa znacznika jQuery elementu
Mam następujące 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>
i JavaScript:
$(".edit").click(function(){
$(this).closest("div.section").children().each(function(){
alert($(this).tagName + " - " + $(this).html());
});
})
próbowałam $(this).tagName
, $(this).nodeName
i $(this).attr("tag")
jak wskazano w pytaniu: Can jQuery provide the tag name?
Ale ja” m zawsze otrzymuję w zamian undefined
. html()
wyświetla się poprawnie. Dlaczego nie mogę uzyskać nazwy znacznika dla każdego elementu?
Możliwa duplikat [jQuery: Pobierz wybrany element name tag] (http://stackoverflow.com/questions/5347357/ jquery-get-selected-element-tag-name) – Druzion