WebMay 9, 2016 · ..means that if bulbon word is in current image src attribute, image will be … WebSep 28, 2016 · When the page loads it is set to the pic_bulboff.gif image, and the Javascript code changes the image to the pic_bulbon.gif image. It uses the same img element for both images, Javascript just changes which image is shown.
Automatically turning light on and off use Javascript
WebThis file contains bidirectional Unicode text that may be interpreted or compiled differently … WebAug 23, 2024 · Bulb On Off JavaScript is a mini project. Create an HTML page with the help of CSS and javascript, when we click on the button … switchform
W3Schools Tryit Editor
WebMar 4, 2016 · 1 You are mixing things up.. Use document.getElementById ('myImage').src = "pic_bulbon.gif"; ____^^--------DOM Element-----------^^_Property_^^--Value--^^ Try this: function changeImage () { document.getElementById ('myImage').src = "pic_bulbon.gif"; } function resetImage () { document.getElementById ('myImage').src = "pic_bulboff.gif"; } WebIf it does, the src attribute is assigned a new value of "pic_bulboff.gif" which changes the picture. If the conditional statement results in FALSE, the src attribute is assigned the value of "pic_bulbon.gif". So when the image is that of a bulb turned off and you click, the bulb image is changed to that of one being turned on. WebNov 22, 2014 · 1 solution Solution 1 The better way to match image src attribute is : JavaScript function changeImage () { var image = document .getElementById ( 'myImage' ); if (image.getAttribute ( 'src' )== "pic_bulbon.gif") { image.src = "pic_bulboff.gif" ; } else { image.src = "pic_bulbon.gif" ; } } This works. Posted 22-Nov-14 7:52am Ishpreet Kaur switch for led cabinet lights