Reputation: 3797
If I want to access a div with class ccc
withing div with ID iii
, I can do
$('#iii .ccc').doStuff();
But how do I access a div with class ccc
within this
div?
$('this .ccc').doStuff()
doesn't seem to work. The context I'm trying to use it in is as follows:
$('.substitute').each(function () {
if (some condition) {
$('this .subcaptain').addClass('team_captain');
}
cnt++;
});
"some condition" is met (tested by logging to console) but the team-captain
class isn't assigned.
The HTML is a bunch of DIVs with the following structure:
<div class='substitute'>
<div class='subcaptain'></div>
</div>
Upvotes: 0
Views: 43
Reputation: 82241
You can use:
$(this).find('.ccc').doStuff()
or
$('.ccc',this).find('.ccc').doStuff()
Upvotes: 4