开发者

Select next rows that have ID.length > 0 in a table

Using only jQuery, how would I select the next rows in a table with an ID length > 0?

In my code, I'm using a hybrid of jQuery and javascript. And it works fine. However, I'd like it to be all in jQuery.

var rowsWithIds = new Array();
var rows = $(myTable).nextAll("tr");
for(var i=0; i < rows.length; i++)
{
    if(rows[i].id.length > 0)
        rowsWithIds[rowsWithIds.length] = rows[i];
}

Perhaps, the solution might loo开发者_JAVA百科k like:

var rowsWithIds = $(myTable).nextAll("tr").has("some selector");

or

var rowsWithIds = $(myTable).nextAll("tr and some selector");

Let me know. Thanks!


The following gets all table-rows with an id, removing all that have an empty id:

var rowsWithIDs = $("tr[id]").not("[id='']");


change

var rows = $(myTable).nextAll("tr");

to

var rows = $(myTable).nextAll("tr[id]");

it will select all tr with id (you should not use id with no value)

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜