Instead of returning the body element Why my command document.firstElementChild.secondElementChild returns undefined?

<!DOCTYPE html>
<html>
<head>
	<title>2nd Code</title>
</head>
<body>
	<h1 class="heading">Lets Experiment in this Journey of Learning</h1>
	<p>
		Hey <em><strong>Raj</strong></em> this is just the beginning of <strong>web devop</strong> <!-- The strong tag basically bold the letters present btw tags-->
	</p>
	<p>
		Yes this is also another paragraph <!--em converts simple to italic style-->
	</p>
	<p>	
		<h1 class="details">My Details</h1>
		<ul id="List">
			<li class="name">Raj yadav</li>
			<li class="section details">ECE 2 Roll-79</li>
			<li class="college-details">Academy of Technology</li>
			<li><a href="https://www.linkedin.com/in/raj-yadav-9a5043112/" target="_blank">LinkedIn Profile</a></li>
		</ul><!--the target is used to open in the new tab not on the current-->
		<h3 id="best-college">The list of Few Best Colleges</h3>
		<ol>
			<li>Academy of technology</li>
			<li>MCKV Institute</li>
			<li>IEM</li>
			<li>IIIT Hyderabad</li>
		</ol>
	</p>
</body>
</html>

1 Like

secondElementChild is not a property, that’s why you get an error.

If you want to get the second one do this:

document.firstElementChild.children[1]; // remember indexes start at 0.

yes thanks for the response.
I found one another way also
document.firstElementChild.lastElementChild–> body
then you can further select within an body elment by doing first second and all

1 Like