modern-web-design-and-development

(Brent) #1

find()


This works very similar to children(), only it looks at both children and
more distant descendants. It is also often a safer bet than children().


Say it’s your last day on a project. You need to write some code to hide all


s that have the class hideMe. But some developers omit
from their table mark-up, so we need to cover all bases for the future. It
would be risky to target the s like this...
1 $('#table tbody tr.hideMe').hide();

... because that would fail if there’s no . Instead, we use find():


1 $('#table').find('tr.hideMe').hide();

This says that wherever you find a in #table with .hideMe, of
whatever descendancy, hide it.


6. .not() vs. !.is() vs. :not()


As you’d expect from functions named “not” and “is,” these are opposites.
But there’s more to it than that, and these two are not really equivalents.


.not()


not() returns elements that do not match its selector. For example:


1 $('p').not('.someclass').css('color', '#f90');

That turns all paragraphs that do not have the class someclass orange.

Free download pdf