How can I get all parent elements that has a certain class and their children has a certain string value in their given attributes via jQuery? -
how can html parent elements has css class called ".example" , children <a></a> elements containing string value sample-section in href attributes via jquery?
here's example:
<li class="example"> <a href="root/sample-section/p01">page 1</a> </li> <li class="example"> <a href="root/sample-section/p02">page 2</a> </li> <li class="example"> <a href="root/another-section/p01">page 1</a> </li> <li class="example"> <a href="root/another-section/p02">page 2</a> </li> i want able first , second <li></li> elements in example (they contain string 'sample-section') via jquery above-mentioned criteria , add other classes them. in advance!
$('a[href*=sample-section]').parent('.example'); http://jsfiddle.net/mblase75/eg82u/
or
$('.example').filter(function(){ return $(this).children('a[href*=sample-section]').length; }); http://jsfiddle.net/mblase75/kwv86/
-- should return same result.
Comments
Post a Comment