I would like to know how can I fetch the lastChild, firstChild and nextSibling content in JavaScript.
This is my sample code:
<div id="main">
<div id="first">content 1</div>
<div id="second">content 2</div>
<div id="third">content 3</div>
</div>
<script>
alert (document.getElementById('main').firstChild.nodeValue);
alert (document.getElementById('main').lastChild.nodeValue);
alert (document.getElementById('first').nextSibling.nodeValue);
</script>
I tried this code, but they did not work ... an empty alert opens only!