Traversing Your Selections

As with the DOM, you can traverse jQuery selected results based on child, sibling, or parent nodes. In fact, traversing your jQuery results is nearly the same as the DOM but with a few more methods at your disposal. The methods for traversing jQuery object nodes include .parent(), .parents(), .children(), .siblings(), .next(), and .prev().

As an example, the following shows finding all child nodes of <li> inside the navbar <ul> shown back in Listing 18.1. Recall that this example in the “Document Object Model (DOM)” section of the chapter was more than five lines of code to get this selection.

var sel = $('#navbar').children('li');

Looping Through Your Selection

As you saw previously, ...

Get Microsoft Visual Studio 2015 Unleashed, Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.