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>
