Relax Breath of Solution.Community tech blog of Sameera Thilakasiri - Consultant UI, UX, RWD Specialist/ Interactive Designer

Just I wanted.. Do you?…

Traversing through filtering

Posted on September 11, 2011 | Comments Off on Traversing through filtering

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>”);

Author
Sameera Thilakasiri By Sameera Thilakasiri
,is a front-end developer based in Colombo, is a blogger and a lifestyle photographer.
Follow him Twitter and Google+. Check out him.

Comments

Comments are closed.