From this:
var $saved = $('#parent').find('a');
How can I now subselect those elements in $saved
which have class myClass
?
I don't want descendents (so find
or children
are no good), I want the subset of $saved.
var $refined = $saved.[something something];
Essentially, I want $refined
to be equal to $('#parent').find('a.myClass');
but to start from $saved
.
Thanks.
You can use filter method:
var $refined = $saved.filter(".myClass");
You can use filter
method.
var $refined = $saved.filter('.myClass');
may be this one can help
var $refined = $saved.filter('.myClass');
http://api.jquery.com/filter/
You can iterate through saved collection to find out the elements with class myClass.
var $refined = $saved.each(function(){
if($(this).attr('class') == 'myClass')
return $(this);
});
Or you can use filter() jquery function to apply selector.
var $refined = $saved.filter('myClass');
$saved.each(function(){
if($(this).hasClass('test')) alert($(this).text());
});