jQuery Syntax

The jQuery syntax is made for selecting HTML elements and to perform some action on those element(s).

Basic syntax is: $(selector).action()

  • A dollar sign to define jQuery
  • A (selector) to “query (or find)” HTML elements
  • A jQuery action() to be performed on the element(s)

Examples:

$(this).hide() – hides current element

$(“p”).hide() – hides all paragraphs

$(“p.test”).hide() – hides all paragraphs with

$(“#test”).hide() – hides the element with id=”test”

The Document Ready Function

This is to prevent any jQuery code from running before the document is finished loading

$(document).ready(function(){

//statements..

});

EXAMPLE:

<html>

<head>

<script text="text/javascript" src="jQuery.js"></script>

<script text="text/javascript">

$(document.ready(function{

alert("hello");

});
</script>

</head>

</html>
Posted in jQuery Tagged with: ,