I m newer to javascript, Now i am getting started to javascript.
Here is the link(run with example):
http://www.w3schools.com/js/tryit.asp?filename=tryjs_intro_lightbulb
Here, i have raised one doubt,
if (image.src.match("bulbon")) {
//do stuff
}
May i know, what is "bulbon" why we have use?
And i tried another one example, Here is my code:
<img width="300px" height="300px" src="dim-bulb.jpg" id="bulb" onclick="changebulb()" alt=bulb"/>
<script>
function changebulb() {
var image=document.getElementById("bulb");
if(image.src.match("bulbon")) {
image.src="dim-bulb.jpg";
}
else {
image.src="bright.jpg";
}
}
When i run my code, it works partially , that is when i click, it will becomes bright, but again i click it didn't show as dim..
May i know what is my mistake?
Thanks in advance.
image.src.match:image- Image tag,src- src attribute,match- Check whether it matches with src attribute's value..