Difference between revisions of "JQuery Sandbox"
From Wikicliki
| Line 8: | Line 8: | ||
<script type="text/javascript"> | <script type="text/javascript"> | ||
$(document).ready(function(){ | $(document).ready(function(){ | ||
| − | + | ||
| − | |||
| − | |||
$("a").click(function(){ | $("a").click(function(){ | ||
var curText= $("#myText").val(); | var curText= $("#myText").val(); | ||
| Line 16: | Line 14: | ||
alert(urlname); | alert(urlname); | ||
}); | }); | ||
| − | |||
$("*", document.body).click(function (e) { | $("*", document.body).click(function (e) { | ||
| Line 23: | Line 20: | ||
$("span:first").text("Clicked on - " + getthething.tagName); | $("span:first").text("Clicked on - " + getthething.tagName); | ||
}); | }); | ||
| − | |||
}); | }); | ||
| Line 41: | Line 37: | ||
</html> | </html> | ||
</pre> | </pre> | ||
| + | |||
| + | this is what happens if you use regular expression | ||
| + | <pre> | ||
| + | $("a").click(function(){ | ||
| + | var curText= $("#element"); | ||
| + | var urlname = curText; | ||
| + | alert(this.href.match(/countrycode=(\w\w)/)); | ||
| + | }); | ||
| + | <pre> | ||
Revision as of 12:53, 22 August 2008
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>
this is what happens if you use regular expression
$("a").click(function(){
var curText= $("#element");
var urlname = curText;
alert(this.href.match(/countrycode=(\w\w)/));
});
<pre>