Bryan is an entrepreneur, software developer, photographer, investor and business adviser with a strong operations background coupled with 16 years of startup, new media, early-stage financing, marketing, technology development, sales and real estate investment experience.

a

Tips: JQuery

Tips: JQuery

jQuery is a fast, small, and feature-rich JavaScript library. It makes things like HTML document traversal and manipulation, event handling, animation, and Ajax much simpler with an easy-to-use API that works across a multitude of browsers.

 

All examples will use the following code:

 

.GET

.get retrieves the DOM elements matched by the jQuery object.

.INDEX

.index searches for a given element from among the matched elements.

.TOARRAY

.toarray retrieves all the elements contained in the jQuery set, as an array.

.FIND

.find moves down the DOM tree and finds all matching elements. The element itself is not included in the search.

would move down the DOM tree and target the following  liIII,  a,  b,  c,  III.find does not include the targeted element, so  B would not be included.

.CHILDREN

.children functions the same as .find, but only moves one level down the DOM tree and targets all children. Like .find, the element itself is not included.

would target only  I,  II,  III, as those are the  li one level immediately down the DOM tree.

.CLOSEST

.closest moves up the DOM tree, including the element itself, until it finds a matching element.

would target the  li with class  B, since .closest begins with the element itself.

would move up the DOM tree and target the  ul with class  one.

.PARENT

.parent also moves up the DOM tree a single level and targets the parent element. The element itself is not included.

would target the parent  ul with class  two.

.PARENTS

.parents moves up the DOM tree and targets all parent elements. The element itself is not included.

would target all parent elements, all the way up to and including <body> and <html> which don’t appear in the above code example.

.NEXT

.next moves down and targets the immediately following sibling. The element itself is not included.

would target the the  li with class  c.

.PREV

.prev functions just like .next, but moves up, targeting the immediately preceding sibling. The element itself is not included.

would target the the  li with class  a.

.SIBLINGS

.siblings targets moves up and down, targeting all siblings. The element itself is not included.

would target both  a and  c.

.next.prev and .siblings (and all of the other traversal methods) can also target specific selectors, so something like

would target the preceding sibling with the class  selector.

.FIRST

.first targets the first element in a set.

would target the first  li in the above code.

.LAST

.last  s the opposite of .first, and targets the last element in a set.

would target the last  li above.


Also published on Medium.