Q:

Create Javascript Program to Make a Light Bulb Turn on and Off

belongs to collection: HTML + Javascript Examples

0

Create A HTML Page With JavaScript When We Click The Light Bulb To Turn On/Off The Light.
When We Click A Button JavaScript Change The Image So We Think Bulb Is On Again Click The It Again Change The Image So Bulb Look Like It Is off This Is A Trick Behind Bulb On/off

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

bulb.html

<!DOCTYPE html>
<html>
<body align="center" bgcolor="#686899">
<h1>JavaScript Can Change Images</h1>

<img id="myImage" onclick="changeImage()" src="pic_bulboff.gif" width="100" height="180">

<h2>Click the light bulb to turn on/off the light.</h2>
<script>

function changeImage() {
var image = document.getElementById('myImage');
if (image.src.match("bulbon")) {
image.src = "pic_bulboff.gif";
} else {
image.src = "pic_bulbon.gif";
}
}

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

Output:

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
Build HTML Video Player Support SD, HD, FHD, UHD R... >>
<< Create A HTML Page With Rollover With A Mouse Even...