how can i get for example all links inside a all ready selected jquery element (this)
$("#container li").each(function(){
$("this a").each(function(){
// links inside this li element
});
});
This does not work is there a other way?
how can i get for example all links inside a all ready selected jquery element (this)
$("#container li").each(function(){
$("this a").each(function(){
// links inside this li element
});
});
This does not work is there a other way?
You could use the .find()
function:
$('#container li').each(function() {
$(this).find('a').each(function() {
// links inside this li element
});
});
or to avoid nested loops you could directly select the links and then fetch the parent li
if needed:
$('#container li a').each(function() {
var parentLi = $(this).parent('li');
});
Alternatively to Darin's proposal, jQuery allows you to define a context node for a selector.
So, you could do this:
var
$listItems = $('#container li'),
// use $listItems as context
$anchors = $('a', $listItems);