开发者

How to get ID value from tables nested in other tables with jQuery

I have the following HTML (a snippet):

                    <td class="ms-vb-title" height="100%">
                      <table class="ms-unselectedtitle" onmouseover="OnItem(this)"
                      ctxname="ctx1" id="5" url=
                      "/Business%20Divisions/5_.000" dref=
                      "/Business Divisions" perm="0x7fffffffffffffff"
                      type="" ext="" icon="icgen.gif||" otype="0" couid="" hcd=""
                      csrc="" ms="0" ctype="Item" cid=
                      "0x010072628A3517FD5F4A8D399BADE8A6D104" uis="512" surl="">
                        <tbody>
                          <tr>
                            <td class="ms-vb" width="100%"><a onfocus="OnLink(this)"
                            href=
                            "/Business%20Divisions/DispForm.aspx?ID=5"
                            onclick="GoToLink(this);return false;" target=
                            "_self">Commercial</a></td>

                          </tr>
                        </tbody>
                      </table>
                    </td>
                  </tr>

Now I want to get the ID of tables with class .ms-unselectedtitle and store them in an array. I do this with:

var businessUnitID = new Array();
$('.ms-unselectedtitle').each(function(){
businessUnitID.push($(this).attr('id'));

the class .ms-unselectedtitle is used in a lot of other places in the html though so I wonder if there's a way to get all IDs of tables with class .ms-unselectedtitle and that has a parent td with class .ms-vb-title? Or get a开发者_运维百科ll ID's of a td, with class .ms-vb-title, table (with class ..ms-unselectedtitle) children?

Thanks in advance.


You can try this, to get all IDs of tables with class .ms-unselectedtitle(and parent TD with class .ms-vb-title):

// filter out all tables with immediate parent td.ms-vb-title
// returns a collection
var ids = $('.ms-unselectedtitle').filter(function() {
    return $(this).parent('td').hasClass('.ms-vb-title');

// from resulting collection, grab all IDs
}).map(function() {
    return this.id;

// convert to array
}).get();

Try it here: http://jsfiddle.net/Nt7zv/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜