javascript - jQuery: navigate to another page by clicking a button -


i'm learning javascript , jquery. i'm trying build simple web page buttons navigate page upon click via switch-case statement.

i've added local jquery script .html file, nothing seems happen when click buttons.

demo can found here: http://jsfiddle.net/vmyly/

the html code is:

<head>  <script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>   $("input[type='button']").click(function() {      switch(this.id) {          case 'x':              window.location.href = "http://google.com";               break;          case 'y':               window.location.href = "http://yahoo.com";               break;          case 'z':               window.location.href = "http://stackoverflow.com";               break;             }         });     </head>  <body>             <input type="button" value="google" style="width:120px" id="x"><br>     <input type="button" value="yahoo" style="width:120px" id="y"><br>     <input type="button" value="stackoverflow" style="width:120px" id="z"><br> </body> 

it works fine in fiddle. prob can think of wrap code in ready(). might not causing problem in fiddle since you've selected onload option.

$(document).ready(function(){     $("input[type='button']").click(function() {         switch(this.id) {             case 'x':window.location.href = "http://google.com"; break;             case 'y': window.location.href="http://yahoo.com"; break;             case 'z': window.location.href = "http://stackoverflow.com"; break;         }     }); }) 

Comments

Popular posts from this blog

java - WrongTypeOfReturnValue exception thrown when unit testing using mockito -

php - Magento - Deleted Base url key -

android - How to disable Button if EditText is empty ? -