Thursday, August 14, 2014

Syntax of jquery with example


The syntax of jquery is :
$(selector).action()
Note:  $ sign is used to give access jquery

           selector is used to select the element of web page
           action is used to perform the action 
Here is an example:
 This is a simple html code for creating page with two paragraph one having id and other class.

<!doctype html>
<head><title>external jquery</title>
<head>
<body>
    <p id="id">This is a id paragraph. </p>
    <p class="class">this is a class paragraph</p>

    <script type="text/javascript" src="js/jquery-1.11.1.min.js"></script>
    <script type="text/javascript" src="js/hide.js"></script>
</body>
</html>

The jquery looks like this :
This is a separate file named as hide.js. This is also an example of external scripting. Inline scripting is done by writing the script on the same html page

$('#id').click(function(){
    $('#id').hide();
});
$('.class').click(function(){
    $('.class').hide();
});

No comments:

Post a Comment