Traversing through filtering

This page discusses - Traversing through filtering

Traversing through filtering

Traversing through filtering

     

Traversing through filtering

Using jQuery, you can traverse through different elements of a web page-randomly or sequentially. JQuery have methods for random selection of element. Also it has method for sequential selection. These methods filter out the element from a html page based on the given conditions.

You can traverse element :

  • Traversing through filtering.
  • Miscellaneous Traversing
  • Tree traversal.

Traversing through filtering

Finding element by filtering has following methods :

METHOD DESCRIPTION EXAMPLE
  . eq() Find Elements by index $("li").eq(2).addClass("drop");
 .filter()   The filter( selector ) method can be used to filter out all elements
from the set of matched elements that do not match the specified
selector(s).
$("li").filter(".middle").addClass("drop");
  .first() Reduce the set of matched elements to the first in the set. ('li').first().css('background-color', 'green');
  .has()  Reduce the set of matched elements to those that have a
descendant that matches the selector or DOM element.
$("ul").has("li").addClass("high");
  .is()  Check the current matched set of elements against a selector and
 return true if at least one of these elements matches the selector.
if ($(this).is(":first-child")) {}
  .last() Reduce the set of matched elements to the final one in the set. $("p span").last().addClass('highlight')
 .map()  Translate a set of elements in the jQuery object into another set of
values in a jQuery array (which may, or may not contain elements).
We can get the sum of the values of the checked inputs:

var sum = 0;
$('input:checked').map(function() {
return sum += (this.value * 1);
});
 .not()  Remove elements from the set of matched elements. $('li').not(':even').css('background-color', 'red');
 .slice()  Selects a subset of the matched elements. Selects all paragraphs, then slices the selection to include
 only the first element.
$("p").slice(0, 1).wrapInner("<b></b>");

Learn from experts! Attend jQuery Training classes.