0

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>
Gaurang Tandon
  • 6,504
  • 11
  • 47
  • 84
sveti petar
  • 3,637
  • 13
  • 67
  • 144

1 Answers1

4

You can use:

$(this).find('.ccc').doStuff()

or

$('.ccc',this).find('.ccc').doStuff()
Milind Anantwar
  • 81,290
  • 25
  • 94
  • 125