I'm wondering how property NextSibling works in case of using method getElementsByClassName() ? Here is an code example showing the problem:
function Sibling() {
var x = document.getElementsByClassName('firstClass')[0];
document.getElementById("out1").innerHTML = 'We are on <b> ' + x.className + '</b>. TypeName of the object is <i> ' + x.constructor.name + '</i>';
x = x.nextSibling;
document.getElementById("out2").innerHTML = 'After SINGLE nextSibling we are on <b> ' + x.className + '</b>. TypeName of the object is <i> ' + x.constructor.name + '</i>. WHY IS THAT???!!!';
x = x.nextSibling;
document.getElementById("out3").innerHTML = 'After DOUBLE nextSibling we are on <b> ' + x.className + '</b>. TypeName of the object is <i> ' + x.constructor.name + '</i>';;
}
<div class="general">
<div class="firstClass">
</div>
<div class="secondClass">
</div>
<button onclick="Sibling()">ClickMeAndThenExplainTheResults</button>
</div>
<p id="out1"></p>
<p id="out2"></p>
<p id="out3"></p>
So, after the very first NextSibling I expected to get on the second element:
<div class="secondClass">
But for uknown reasons you need to call double NextSibling to move from the first element to the second one.
And as you can see after the first NextSibling the TypeName of the object is Text. But I don't see any text actually...
Could you please explain why we need using two NextSibling and what's the Text object is getting after using the first NextSibling?