I need to get all html contents in the span element containing the test class name. But I can't get this content if it is inside the p tag.
let content = document.querySelectorAll('span.test');
for (i = 0; i < content.length; i++)
{
alert("CONTENT: "+content[i].innerHTML);
}
<span class="test">normaltext1<span>spantext</span>normaltext2<div>divtext</div>normaltext3</span>
This code working but when I added p tag to content (to first and last ) this code didn't worked.
let content = document.querySelectorAll('span.test');
for (i = 0; i < content.length; i++)
{
alert("CONTENT: "+content[i].innerHTML);
}
<p><span class="test">normaltext1<span>spantext</span>normaltext2<div><div>divtext</div>normaltext3</span></p>
Result is : CONTENT: normaltext1<span>spantext</span>normaltext2
Content starting with div is not coming after normaltext2
jsFiddle Link: https://jsfiddle.net/106gy4hs/
How can I do this?