javascript switch case not working properly? -


i have following code , using switch case switch src of pictures button.. don't know why first case's "alert" not functoning..

<div id="main_img">    <center>      <button style="width:100;height:100" onclick="lastpic();"><---</button>      <img id="img" src="13.jpg" height=70% width=70%>      <button style="width:100;height:100" onclick="firstpic();">---></button> </div>  <script>    var james = document.getelementbyid("img").getattribute('src');    document.write(james);     function firstpic(){       switch (james){          case "12.jpg":             document.getelementbyid("img").src = "13.jpg";          break;          case "13.jpg":             document.getelementbyid("img").src = "14.jpg";          break;          case "larry":              alert('hey');          break;          default:              alert('default case');          break;      }    } </script> 

try working fine.

<script src="http://code.jquery.com/jquery-1.10.1.min.js"></script> <script> function myfunction() { var src = $('img[alt="example"]').attr('src'); alert("source of image alternate text = example - " + src);  switch (src) {    case "12.jpg": document.getelementbyid("img").src = "13.jpg"; break;     case "13.jpg":     alert('sa');     document.getelementbyid("img").src = "14.jpg"; break;     case "larry":         alert('hey');        break;     default:         alert('default case');        break; } } </script> <div id="main_img">  <button style="width:100;height:100" onclick="lastpic();"><--- </button>  <img alt="example" id="img" class="imagess" src="13.jpg" height=70% width=70%> <button style="width:100;height:100" onclick="myfunction();">---></button> </div> 

Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

c# - must be a non-abstract type with a public parameterless constructor in redis -

ajax - PHP/JSON Login script (Twitter style) not setting sessions -