Jquery: tricky selector question

jquerynestedselector

hi i'm having this markup:

<div id="main">
     <div nam="item">1</div>
     <div nam="item">2</div>

     <div>
           <div nam="item">3</div>
           <div nam="item">4</div>
           <div nam="item">5</div>
     </div>

     <div nam="item">6</div>
     <div nam="item">7</div>
</div>

i'm now selecting only the direct child divs by using this method:

var divs = $("#main > [nam]"

my question – i want to do this inside a function where i only pass the parent div, how would i need to change the selector?

function get_rootChildren(div)
{
      return($("* > [nam]",div));
}

^ this is bogus but i think u know what i mean – how could this be done?
thx, fuxi

Best Solution

Perhaps:

$("#main > div.item")

From jQuery Selector Docs

parent > child

Matches all child elements specified by "child" of elements specified by "parent".

To answer part two - I would use .children() something like this:

function get_rootChildren(div) {
   $(div).children('div.item');
}