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
  • 48,855
  • 59
  • 128
  • 165

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
  • 339,989
  • 67
  • 413
  • 406
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
  • 41,293
  • 8
  • 87
  • 103
1

using children

 $(this).children('div')

or using find

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

look on this post

Community
  • 1
  • 1
Haim Evgi
  • 123,187
  • 45
  • 217
  • 223
0

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

var children = $self.children();
Matt
  • 74,352
  • 26
  • 153
  • 180
Fermin
  • 34,961
  • 21
  • 83
  • 129