phpeveryday.com

The best tutorial of php, php framework, php strategies, object oriented oriented,


jQuery - Selectors: Understanding The $() Factory Function

Tag: jQuery, $(), factory, function, selectors   Category: JavaScript
post: 21 Mar 2008 read: 622


jQuery Selector Step By Step Tutorial - Part 1: Before read this series about jQuery selector, please read jQuery introduction. Now, we talk important function at jQuery, $() Factory function.

How to use $() factory function, look at following examples:

  • A tag name: $('p') gets all paragraphs in the document.
  • An ID: $('#song-id') gets the single element in the document that has the corresponding song-id ID.
  • A class: $('.lyric-class') gets all elements in the document that have a class of lyric-class.

For practice in this series, create a file named "selectors.html". Enter following code:


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Beatles Song</title>
</head>
<h1>My Favorite Beatles Song</h1>
<div id="description">These is all of my favorite song from The Beatles. How about you?</div>

<ul id="favorite">
  <li>Love
    <ul>
      <li><a href="love.html">Love me do</a>
      <li>Something
      <li>Here, There, and Anywhere
    </ul>
  <li>Balads
    <ul>
      <li><a href="obladi.pdf">Obladi Oblada</a>
      <li>Get Back
      <li>Help
    </ul>
  <li>Rock 'n Roll
    <ul>
      <li><a href="mailto:music.rock">Rock 'n Roll The Music</a>
        <ul>
          <li>Part 1
          <li>Part 2
        </ul>
      <li>Hard Days Night
      <li>Standing There
    </ul>
</ul>

<body>
</body>
</html>



Series this article:
jQuery - Selectors: Understanding The $() Factory Function
jQuery - Selector: Modifying Style at List Item Levels
jQuery - Selector: Styling Sub Level Item
jQuery - Selector: XPath Selectors
jQuery - Selector: Custom Selectors
jQuery - Selector: Choose a Style at Custom Selectors
jQuery - Selector: Modify Style for Table Header
jQuery - Selector: Styling Sibling
jQuery - Selector: Styling Next Cell

| Give Your Opinion | Recommend
Share and Bookmark to: These icons link to social bookmarking sites where readers can share and discover new web pages.
digg del.icio.us technorati Ma.gnolia BlinkList

Recommended articles by other readers:
Web Services: How PHP Kiss VB.NET? (Part 1)
Chart: How to Build Cool Animation Real Time Chart
Joomla: Fast Road to Understand Component Programming
Email: Send Attachement Mail
mod_rewrite - Part 1: create your "fantasy" URL

What do You Think?
Your Name *:
Email *:
(Will not be published)
Website/URL:
Your Comment *:
* Required


615
posting