Quick Reach
jQuery Syntax
As such with jQuery HTML elements are selected and certain actions are performed on these elements. Syntax of jQuery is made accordingly:
$(selector).action()
So this is the basic syntax of jQuery where
- $ = define or access jquery
- (selecter) = is to find or refer HTML elements
- Action() = jQuery action to perform on those elements
For example: $(“.resultset”).hide() Here $sign accesses jquery, which performs action to hide resultset class.
A basic example of jQuery
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
<html>
<head>
<title>jQuery Testing</title>
<script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
<script type="text/javascript" language="javascript">
$(document).ready(function() {
$("p").click(function () {
$(".resultset").hide();
});
});
</script>
</head>
<body>
<p>Click here to hide resultset class below:</p>
<div class="resultset" style="background-color:yellow;">
This is Yellow line!!
</div>
</body>
</html>
|
So in the above example, if you click on “Click here to hide resultset class below:” text in browser it will hide yellow line with text . The “Click here to hide resultset class below:” is contained in <p> of and Yellow line in div class resultset. So what actually this jquery code does:
– <script src=”http://code.jquery.com/jquery-1.10.1.min.js”></script> lines is used to call reference for jQuery library.
– $(document).ready(function() of jquery is explained here, that ensures if document is loaded then execute java script
– Next lines $(“p”).click(function () specifies if paragraph is clicked anywhere then it will hide running this code $(“.resultset”).hide();
Leave A Comment?