Is there a jQuery selector that return all descendant that are 'first of type'?

For example, consider this markup:

<table>
   <tr>
    <td>
      <div id="d1">
         <div>222</div>
         <div>333</div>
      </div>
    </td>
   </tr>
   <tr>
    <td>
      <p>
         <div id="d1_1">
          <div>222</div>
         </div>
      </p>
    </td>
   </tr>
</table>

EDIT: I would like to get only the DIVSs "d1" and "d1_1"

Thanks

Answers


$('td').find('div:first')

This says, find the first div in each td.

Just for fun, this would find those NOT the first one:

$('td').find('div:not(:first)')

See this (slightly modifed) example: http://jsfiddle.net/ezaHU/

I modified it to add text to the second examples td so it would show in the example.

AND just for complete example, if you ONLY have an id on those:

$('td').find('div[id]')

But I did not think that is what you were aiming for based on the progression of your edits.


Need Your Help

View Worker Role trace lines and log files

c# logging azure cloud azure-worker-roles

I have .Net Worker role (Azure) and my application write to local log files in this form:

Bootstrap - How to make text wrap around an image on small devices?

css image twitter-bootstrap

I'm just getting started with Bootstrap. Below is a snapshot of my page.