title: jQuery - get all divs inside a div with class ".container"
body: <p><strong>Scenario:</strong></p>
  
  <p>I got a menu containing links:</p>
  
  <pre><code>Main Menu Item
  --------------
  Sub: Show Grid &gt; SubSub: &lt;a&gt;Show #first&lt;/a&gt;
                           &lt;a&gt;Show #second&lt;/a&gt;
                           &lt;a&gt;Show #third&lt;/a&gt;
  </code></pre>
  
  <p>Now i need to find all divs with an css <code>#ID</code> who are first level DOM elements inside the <code>.container</code> div. These elements should get appended to "Sub: Show Grid" and add a class via a click on it. </p>
  
  <pre><code>&lt;!-- The mark up --&gt;
  &lt;div class="container"&gt;
      &lt;div id="first"&gt;1st&lt;/div&gt;
      &lt;div id="second"&gt;2nd&lt;/div&gt;
      &lt;div id="third"&gt;3rd&lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p><strong>Question:</strong> </p>
  
  <ul>
  <li>How would i find the first level div with an (undefined/not known) <code>#ID</code> with jQuery?</li>
  <li>How can i interact with the result in php - will I get an array as result to build the SubSub menu out of it?</li>
  </ul>
  
  <p><strong>Thanks in advance!</strong></p>
  
  <hr>
  
  <p><strong>Edit #1</strong></p>
  
  <p>To make it more clear what I'm trying to do - In pseudo code:</p>
  
  <pre><code>$divs_received_from_jquery_fn = 'how do I get the divs (IDs?) as array(?) and interact with them in the following code?';
  foreach ( $divs_received_from_jquery_fn as $div )
  {
      add_menu_item( array( 
           'parent' =&gt; 'Sub: Show Grid'
          ,'name'   =&gt; 'Show #'.$div
          ,'href'   =&gt; ''
          ,'meta'   =&gt; array( 
                          'onclick' =&gt; 'jQuery(".container #".$div).toggleClass("showgrid");'
           ) 
      ) );
  }
  </code></pre>
  
  <p><strong>Edit #2</strong></p>
  
  <p>The "real world" example. The output is an onclick event for an a-link. My problem is that i want to call the function <code>foreach</code> for every <code>div[id]</code> below the <code>.container</code> div and simply don't know how to interact properly with javascript &amp; php.</p>
  
  <pre><code>?&gt;
  &lt;script type="text/javascript"&gt;
      jQuery(".container &gt; div[id]").each(function(){
          var context = $(this);
          &lt;?php 
          // SHOWGRID - parts
          // @since v0.3
          $wp_admin_bar-&gt;add_menu( // trigger the function via the global $wp_admin_bar var that calls the class
              array(
                   'parent'   =&gt; 'showgrid' // parent menu item
                  ,'id'       =&gt; 'showgrid - ' + this.id // menu item ID
                  ,'title'    =&gt; sprintf( // menu item label
                       __( '%1$s show grid parts %2$s%3$s', OXO_TEXTDOMAIN )
                      ,'&lt;span style="background: none;"&gt;'
                      ,'&lt;span class="showgridparts-on hide"&gt;&amp;#x2714;&lt;/span&gt;'
                      ,'&lt;span class="showgridparts-off"&gt;&amp;times;&lt;/span&gt;' 
                   )
                  ,'href'     =&gt; '' // stays empty to not trigger anything
                  ,'meta'     =&gt; array( // HERE GOES THE ACTUAL jQuery FUNCTION
                      'onclick'   =&gt; 'jQuery("#" + this.id).toggleClass("showgrid"); jQuery(".showgridparts-on").toggleClass("hide"); jQuery(".showgridparts-off").toggleClass("hide"); return false;'
                   )
              ) 
          );
          ?&gt;
      });
  &lt;/script&gt;
  &lt;?php
  </code></pre>