2
$('#cont > fieldset').each(
function(index){
        var $self = $(this);
        // Here how to get child elements? How to write this selector?
        //$('$self > div') ?? this seems does not work.


});
user469652
  • 44,657
  • 57
  • 123
  • 163

4 Answers4

2
$self.find("div"); // return all descendant divs

or:

$self.children("div"); // return immediate child divs

depending on whether you want immediate children or any descendants.

You can even do this to get immediate child divs, but children is prettier :

$self.find(">div");
karim79
  • 334,458
  • 66
  • 409
  • 405
1

Look at the .children method in jQuery. This will get direct children of the element, e.g.:

$self.children('div') // returns divs that are direct children

You can also use the similar .find method if you need to go deeper than one level.

$self.find('div') // returns divs that are direct children, or children of children

Also, you can select using $self as the context, like:

$('div', $self) //returns all divs within $self
sje397
  • 40,327
  • 7
  • 84
  • 103
1

using children

 $(this).children('div')

or using find

$(this).find('div');

look on this post

Community
  • 1
  • 1
Haim Evgi
  • 120,002
  • 45
  • 212
  • 219
0

You can use the children() method, to get all immediate children of self.

var children = $self.children();
Matt
  • 72,564
  • 26
  • 147
  • 178
Fermin
  • 33,739
  • 20
  • 84
  • 127