Showing posts with label jQuery. Show all posts
Showing posts with label jQuery. Show all posts

22 October 2010

jQuery effects

Hide, Show, Toggle, Slide, Fade, and Animate. WOW! With all these, you already can create quite an interactive web pages! Amazing jQuery!

http://www.w3schools.com/jquery/jquery_effects.asp

Okay, enough of jQuery lessons for today!

jQuery selector concept

In HTML DOM terms:

Selectors allow you to manipulate DOM elements as a group or as a single node.

jQuery Element Selectors

jQuery uses CSS selectors to select HTML elements.


$("p") selects all elements.
$("p.intro") selects all elements with class="intro".
$("p#demo") selects the first element with id="demo".


jQuery Attribute Selectors

jQuery uses XPath expressions to select elements with given attributes.


$("[href]") select all elements with an href attribute.


$("[href='#']") select all elements with an href value equal to "#".


$("[href!='#']") select all elements with an href attribute NOT equal to "#".


$("[href$='.jpg']") select all elements with an href attribute that ends with ".jpg".

jQuery syntax for selecting HTML elements

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

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

  • dollar sign to define jQuery
  • (selector) to "query (or find)" HTML elements
  • 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 class="test"

$("#test").hide() - hides the element with id="test"


P.S. jQuery uses a combination of XPath and CSS selector syntax.