Element only Navigation in JavaScript
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<link rel="stylesheet" href="../CSS/Element_only_Navigation.css">
<title>Element only Navigation</title>
</head>
<body><!--This is me-->
<nav>
<ul>
<li>Home</li>
<li>About Me</li>
<li>Hire me</li>
</ul>
</nav>
<div class="container">
<p>Hey I am a good boy</p>
</div>
<script src="../Element_only_Navigation.js"></script>
</body>
</html>
Below File is Element_only_Navigation.js File.
const changeBgRed = () => {
document.body.firstElementChild.style.background = "red";
}
let b = document.body;
console.log("First child of b is : ", b.firstChild);
console.log("First Element child of b is : ", b.firstElementChild);
Below File is CSS/Element_only_Navigation.css File.
.png)
.png)
.png)
.png)
.png)
.png)
.png)
.png)
Comments
Post a Comment