Help, the same with value at input worked, but not here, if that, here is a link to the page: duoxx.imtqy.com

<!DOCTYPE html> <html> <head> <title>Javascript Tutorial</title> <link rel="stylesheet" type="text/css" src="main.css"/> <script type="text/javascript"> function ClickButton (TypeImg) { if(TypeImg.src == "dor.gif"){ alert ("hello"); } } </script> </head> <body> <img alt="Doritos" src="dor.gif" onclick="ClickButton (this)" style="cursor:pointer;"/> </body> </html> 

  • In TypeImg.src gets the full path to the image, because the equality is not performed. So either check for a complete match with the absolute path, or for an incomplete match with a regular schedule, or enter a dubbing attribute and check with it. - br3t

1 answer 1

To get exactly what is specified in the src your image, you can use getAttribute('src') :

 <!DOCTYPE html> <html> <head> <title>Javascript Tutorial</title> <link rel="stylesheet" type="text/css" src="main.css" /> <script type="text/javascript"> function ClickButton(TypeImg) { if (TypeImg.getAttribute('src') == "dor.gif") { alert("hello"); } } </script> </head> <body> <img alt="Doritos" src="dor.gif" onclick="ClickButton (this)" style="cursor:pointer;" /> </body> </html> 

  • Thanks a lot! I started learning javascript recently rather on this :) - ishidex2