Q: trying to alert the secondchild's innerhtml in javascript Here is a code snippet which try to alert the secondchilds innerhtml.but it is not showing anything.
Here is the fiddle
https://jsfiddle.net/user1989/3cbzahfo/6/
<!DOCTYPE html>
<html>
<head>
<script>
function iclick() {
  alert(document.getElementById("i").secondChild.innerHTML);
}
</script>
</head>
<body>

<div id="i" >
  <p>second</p>
  <p>fourth</p>
  <p>sixth</p>
  <div id="ii" onclick="iiclick()">The first child</div>
</div>
<button onclick="iclick()">Trythis</button>
</body>
</html>


A: secondChild is not a valid property, you can use children instead and use index


<!DOCTYPE html>
<html>

<head>
  <script>
    function iclick() {
      alert(document.getElementById("i").children[1].innerHTML);
    }
  </script>
</head>

<body>

  <div id="i">
    <p>second</p>
    <p>fourth</p>
    <p>sixth</p>
    <div id="ii" onclick="iiclick()">The first child</div>
  </div>
  <button onclick="iclick()">Trythis</button>
</body>

</html>



If you just want the p tag, then use getElementsByTagName()


<!DOCTYPE html>
<html>

<head>
  <script>
    function iclick() {
      alert(document.getElementById("i").getElementsByTagName('p')[1].innerHTML);
    }
  </script>
</head>

<body>

  <div id="i">
    <p>second</p>
    <p>fourth</p>
    <p>sixth</p>
    <div id="ii" onclick="iiclick()">The first child</div>
  </div>
  <button onclick="iclick()">Trythis</button>
</body>

</html>



A: 

function iclick(){
alert(document.getElementById("i").getElementsByTagName('p')[1].innerHTML);
}
<div id="i" >
<p>second</p>
<p>fourth</p>
<p>sixth</p>
<div id="ii" onclick="iiclick()">The first child</div></div>
<button onclick="iclick()">Trythis</button>


secondChild is not a valid property. The getElementsByTagName() method returns a collection of all elements in the document with the specified tag name, as a NodeList object.
The NodeList object represents a collection of nodes. The nodes can be accessed by index numbers. The index starts at 0.
Try this instead:
 function iclick(){
 alert(document.getElementById("i").getElementsByTagName('p')[1].innerHTML);
 }

Here is the Updated Fiddle

A: I would suggest you to use childnodes concept and indexs,However it will count new line characters too as the child nodes .
console.log(document.getElementById("i").childNodes[4]);
