This is simple project describes the use of the CSS and jQuery by an simple project here we use the CSS filter : grayscale to turn off the light following video is useful to undestand hoe to works
Following work is divided and implemented in few steps
-> Basic html page with buttons to ON and OFF and light image
<html>
<head>
<title></title>
</head>
<body>
<button >turn off the light</button>
<button >turn on the light</button>
<div >
<img src="new.png">
</div>
</body>
</html>
-> Add some CSS to buttons turn OFF the light ( Here we are using class names to apply Style )
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.0/jquery.min.js"></script>
<script type="text/javascript">
//using jquery makes the work easy compared to javascript
//code to remove and add the grayscale class
$('.right').click(function(){
$('div').removeClass('grayscale');
});
$('.off').click(function(){
$('div').addClass('grayscale');
});
</script>
The whole code assembled
<html>
<head>
<title></title>
</head>
<style type="text/css">
body{
background: url(background.jpg);
}
.grayscale{
-webkit-filter: grayscale( 100% );
}
.right{
float: right;
}
button{
font-size: 20px;
background-color: black;
color: white;
}
</style>
<body>
<button class="off">turn off the light</button>
<button class="right">turn on the light</button>
<div class="light grayscale">
<img src="new.png">
</div>
</body>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.0/jquery.min.js"></script>
<script type="text/javascript">
//to write the code to remove and add the grayscale class
$('.right').click(function(){
$('div').removeClass('grayscale');//using jquery makes the work easy compared to javascript
});
$('.off').click(function(){
$('div').addClass('grayscale');//using jquery makes the work easy compared to javascript
});
</script>
</html>