jQuery - SPLessons
SPLessons 5 Steps, 3 Clicks
5 Steps - 3 Clicks

jQuery Syntax

jQuery Syntax

shape Description

jQuery Syntax is to select specific elements from HTML document and perform some action on selected elements with manipulation in Dot sign ..

shape Syntax

$(selector).action()
where
  • $ sign is used to define/access a jQuery library. jQuery library is actually declared in a variable called jQuery.
  • selector define the Query or select a specific element from HTML document.
  • action() define the action() to be performed on selected elements of HTML document.

jQuery Basic Syntax Examples

shape Example

$("p").hide() : hide() function of jQuery hides all current <p> elements. In this below example : $ sign defines the jQuery library, p element is the selector and it will select all p elements of HTML document, hide() function is action to hide all current visible p elements of HTML document. [html] <html> <head> <title>jQuery Syntax</title> </head> <body> <h1>Welcome to SPLessons</h1> <p>This is a first paragraph</p> <span>This is a span element</span> </body> </html> [/html] [javascript] $(document).ready(function() { $("p").hide(); }); [/javascript] Output: Fade in/Fade out : This involves of hiding and showing html elements using nice fading effects. It is well used to show or hide a div and its content in a proper way.

Summary

shape Key Points

  • jQuery Syntax selects HTML elements and perform action on selected elements.
  • $ accesses jQuery,selector selects HTML elements and action is a function performing some action on specified element.