jQuery in Action

8
CHAPTER 1
Introducing jQuery
var elements = $("div.fillMeIn");
for(i=0;i<elements.length;i++)
elements[i].innerHTML =
"I have added some text to a group of nodes";
As things get progressively more complicated, leveraging jQuery's chainability
will continue to reduce the lines of code necessary to produce the results that you
want. Additionally, jQuery supports not only the selectors that you have already
come to know and love, but also more advanced selectors--defined as part of the
CSS
Specification--and even some custom selectors.
Here are a few examples.
$("p:even");
This selector selects all even
<p>
elements.
$("tr:nth-child(1)");
This selector selects the first row of each table.
$("body > div");
This selector selects direct
<div>
children of
<body>
.
$("a[href$=pdf]");
This selector selects links to PDF files.
$("body > div:has(a)")
This selector selects direct
<div>
children of
<body>
-containing links.
Powerful stuff!
You'll be able to leverage your existing knowledge of
CSS
to get up and run-
full list at http://docs.jquery.com/Selectors.
Selecting
DOM
elements for manipulation is a common need in our pages, but
some things that we also need to do don't involve
DOM
elements at all. Let's take
a brief look at more that jQuery offers beyond element manipulation.
1.3.2 Utility functions
Even though wrapping elements to be operated upon is one of the most frequent
uses of jQuery's
$()
function, that's not the only duty to which it's assigned. One of
its additional duties is to serve as the namespace prefix for a handful of general-
purpose utility functions. Because so much power is given to page authors by the
jQuery wrapper created as a result of a call to
$()
with a selector, it's somewhat rare


Другие страницы

 
Cкачать книги бесплатно без регистрации в электронном виде (pdf, chm, txt).Вы можете читать книги онлайн на нашем сайте литературного портала книг.Большая подборка учебников, пособий, интересных книг.Электронные книги на английском языке скачать бесплатно без смс.