Friday, August 12, 2022

Js - Skills Events 3 solution

Made like recomended

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>skills 3 Events</title>
    <style>
        * {
            box-sizing: border-box;
        }
        button {
            display: block;
            margin: 20px 0 20px 20px;
        }
        .button-bar {
            padding: 20px 0;
        }
    </style>
</head>
<body>

    <section class="preview">

    </section>

    <h1>skills 03  Events</h1>
    <div class="button-bar">
        <button data-color="red">Red</button>
        <button data-color="yellow">Yellow</button>
        <button data-color="green">Green</button>
        <button data-color="purple">purple</button>
    </div>

    <script>

        const buttonBar = document.querySelector('.button-bar');
        //const butt = document.querySelectorAll('button');

        buttonBar.addEventListener('click', (event)=>{
            document.body.style.backgroundColor = event.target.dataset.color;
        })


    </script>
</body>
</html>

Rute Bezerra de Menezes Gondim

No comments:

Post a Comment