JQuery Syntax


JQuery needs to select HTML elements to act upon.

    Syntax:

    $(selector).action()
  • $ defines to access mentioned HTML element.
  • (selector) finds HTML element where JQuery is to act.
  • action() defines JQuery action to be performed on selected HTML element.

Example:

$("div").hide()-Hides all the HTML div elements.

Document Ready

We use this method so that JQuery starts working only when entire web page has loaded.This because if one clicks a button but the action that is to be performed is not loaded on web page then what action will that do.

    Syntax:

  • $(document).ready(function(){
    Statement
    })
    ;

JQuery Selectors

Selectors in JQuery are used to select mentioned or desired HTML element and to upon them to make them responsive.
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com
/ajax/libs/jquery/1.11.3/jquery.min.js">
</script>
<title>
JAVASCRIPT
</title>
</head>
<body>
<div class="example">
This is DIV element.
</div>
<button>
Click
</button>
<script>
$(document).ready(function(){
$("button").click(function(){
$(".example").hide();
});
});
</script>
</body>
</html>

Output:

This is DIV element.
Here JQuery first checks whether button is clicked or not and if button is clicked then it selects element with class example and hides that.