2012-12-21 54 views
0

我试图寻找我的所有div一定文本“www.url.com”提取IDjQuery的查找文本和子元素

如果www.url.com发现我想提取表ID来自子表。

我的HTML是这样的:

<div class="box" id="results"> 
    <div class="box-header"> 
     <h1>www.url.com</h1> 
    </div> 
    <table cellpadding="0" cellspacing="0" border="0" class="display" id="24"> 
     <thead> 
     <tr> 
      <th>col</th> 
     </tr> 
     <tr id="161"> 
      <td class="kw" style="border-left: 1px solid white;border-right: 1px solid #F4F4F4;padding: 12px 14px;position: relative;text-align: left;">111111</td> 

     </tr> 
     </thead> 
     <tbody></tbody> 
    </table> 

在这种情况下,我想找到ID = “24”。

这是我到目前为止有:

var foundin = $('*:contains("www.url.com")'); 

不知道如何获得ID :)

回答

3

用途:

foundin.find('table').attr('id'); 

如果你想收集所有情况下使用是这样的:

foundin.each(function(){ 
    $(this).find('table').attr('id'); // Gets the ID 
    // Store it into something like an array 
}); 
+0

完美的作品!谢谢:) – Elvin

+0

不用担心,随时接受! –

+0

将在6分钟内完成 – Elvin

0

试试这个,如果所有的表看起来都一样,这应该工作。

$('*:contains("www.url.com")').find('table:first').attr('id'); 
0
var tableId = $('*:contains("www.url.com")').closest('.box').find('table').attr('id');