简体   繁体   中英

jQuery - How to select tablerow element using custom attribute value?

I have some HTML similar to this, where a custom attribute value has been programmatically applied to rows in a table:

<table>
    <tr RowID="123">
        <%-- elements in row --%>
    </tr>
    <tr RowID="457">
        <%-- elements in row --%>
    </tr>
</table>

Using jQuery, how can I select a row based on a particular RowID value so that I can show/hide that row?

I've tried the following which doesn't seem to work:

$("tr[RowID='" + rowID + "']").show();

What you have works fine - http://jsfiddle.net/e94W2/1

Is your coding inside a $(document).ready(function() { }) block like this?

$(document).ready(function() {
    var rowID = 123;
    $('tr').hide();
    $("tr[RowID='" + rowID + "']").show();
});

If not it probably cant find the tablerow as it hasnt been loaded yet.

如果您在表中使用分页,那么该行可能不在当前页面上,因为如果加载了行,那么您的代码就可以了。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM