h
<html>
<head>
<title>jQuery demo</title>
<!-- Link to both jQuery and jQuery UI -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/jquery-ui.min.js"></script>
</head>
<body>
<h2> <a href="http://www.nyu.edu">NYU</a> <br>
<a href="http://cs.nyu.edu">CS Dept.</a> </h2>
<script>
$("a").click(function(event){
alert("As you can see, you are about to follow the link");
});
</script>
</body>
</html>
See the code run
The jQuery syntax is tailor made for selecting HTML elements and performing some action on the element(s).
Basic syntax is: $(selector).action()
• A $ sign to define/access jQuery • A (selector) to "query (or find)" HTML elements • A jQuery action() to be performed on the element(s)
Examples:
$(this).hide() - hides the current element. $("p").hide() - hides all <p> elements. $(".test").hide() - hides all elements with class="test". $("#test").hide() - hides the element with id="test".
<html>
<head>
<script
src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"> </script>
</head>
<body>
<h3>Make the following paragraphs vanish!</h3>
<p>Click this and make it disappear!</p>
<p>This will vanish also!</p>
<p>One, more and it's all gone!</p><script>
$("p").click(function(){
$(this).hide();
});
</script></body>
</html>
See the code run
<html>
<head>
<script
src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js">
</script>
<script>
// Wait until the HTML loads
$(document).ready(function(){
$("p").click(function(){
$(this).hide();
}); /* end p.Click */
}); /* end document.ready */</script>
</head>
<body>
<h3>Make the following paragraphs vanish!</h3>
<p>Click this and make it disappear!</p>
<p>This will vanish also!</p>
<p>One, more and it's all gone!</p>
</body>
</html>