0

例如,考虑这个标记:

<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>

编辑:我想只得到 DIVS“d1”和“d1_1”

谢谢

4

3 回答 3

1
$('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.

于 2012-04-04T12:08:17.543 回答
0

You can use children() like:

$('td').children('div')

See this fiddle

EDIT: Re-reading your question, in case you know all IDs you can also just do:

$('#d1, #d1_1')
于 2012-04-04T12:07:42.420 回答
0

编辑后你想要这个:

$('div:contains("111"):parent');
于 2012-04-04T11:51:50.850 回答