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,110
  • 10
  • 44
  • 79
sveti petar
  • 3,626
  • 12
  • 58
  • 122

1 Answers1

4

You can use:

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

or

$('.ccc',this).find('.ccc').doStuff()
Milind Anantwar
  • 79,642
  • 23
  • 92
  • 120