Javascript Project to Turn ON/OFF Light Bulb on Button Press in Browser Full Project For Beginners

 

 

index.html

 

 

<!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="style.css">
    <title>Light Switching</title>
</head>
<body>
    <div class="canvas">
        <h1>Turn the light on and off </br>by clicking the bulb!</h1>
        <div id="bulb" class="bulb-off"></div>
    </div>
    <script src="app.js"></script>
</body>
</html>

 

 

app.js

 

 

const light = document.querySelector('#bulb');

light.addEventListener('click', function(e){

    e.target.classList.toggle('bulb-on');

})

Leave a Reply