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.
html,
body {
    height: 100%;
    width: 100%;
    margin: 0;
    padding: 0;
}

ul {
    display: flex;
    background: #808080;
    margin: 0;
    padding: 15px 0;
    color: #ffffff;
}

ul li {
    list-style: none;
    margin: 0 23px;
}










Comments

Popular posts from this blog

Generators tutorial in Advance JavaScript

Document Object Module DOM querySelector and querySelectorAll tutorial in JavaScript

Find Even and Odd Numbers with Loops tutorial in JavaScript