Difference between revisions of "JQuery Sandbox"

From Wikicliki
Jump to: navigation, search
Line 1: Line 1:
 +
http://effectize.com/jquery-developer-guide
 +
 
== experiment one ==
 
== experiment one ==
  

Revision as of 13:36, 3 September 2008

http://effectize.com/jquery-developer-guide

experiment one

this experiment prints the contents of the textarea in an alert, and also prints the tagname of the clicked items into the first span tag available....

  <html>
  <head>
    <script type="text/javascript" src="jquery.js"></script>
    <script type="text/javascript">
  $(document).ready(function(){

 $("a").click(function(){  
 var curText= $("#myText").val(); 
  var urlname = curText;
   alert(urlname);
 });
 
     $("*", document.body).click(function (e) {
      e.stopPropagation();
      var getthething = $(this).get(0);
      $("span:first").text("Clicked on - " + getthething.tagName);
    });

 });
    </script>
  </head>
  <body>
  
  
    <a name="namename" id="idname" href="index2.html"> non nummy bong bong</a>
	<br><br>
	<span class=first></span>
	<br><br>
	
<textarea name="myText" rows="5" cols="20" id="myText" style="width:250px;"></textarea> 
	
  </body>
  </html>

assuming im trying to get the countrycode from a url thats like "summerisle?countrycode=SM" and you want to retrieve just the code at the end. you can use jquery along with Regular Expressions

 $("a").click(function(){  
 var curText= $("#element");
  var urlname = curText;
   alert(this.href.match(/countrycode=(\w\w)/));
 });


alternatively you can do the same thing with substrings

  $("a").click(function(){  
	var countryname = this.href;
	var countrycode = countryname.substring(countryname.length-2);
       alert(countrycode);
});