venkat venkat - 6 months ago 24
jQuery Question

How to Get all nodeName inside div tag in jquery?

I need to get all elements

nodeName
using jQuery. I am trying, yet I am only able to get a single element's
nodeName
.

<div class="module">
<p class="aa">Lorem Ipsum</p>
<p>Lorem Ipsum</p>
<p>Lorem Ipsum <span>Test</span></p>
<span>This span</span>
</div>


thanks & regards
Venkat

Answer

You can loop through the children() of the div, and retrieve the nodeName property from each, like this:

$('.module').children().each(function() {
    var nodeName = this.nodeName;
    console.log(nodeName);
})

Working example