Filtering: How to hide/show (toggle) certain table rows on click?

后端 未结 2 864
野性不改
野性不改 2021-01-29 12:07

Assuming this table (actually it could have more columns and rows):

Type Color&
2条回答
  •  自闭症患者
    2021-01-29 12:47

    $(function () {
        $( "td" ).on( "click", function() {
            var type = $(this).text();
            $('td:first-child').parent('tr:not(:contains('+type+'))').toggle();
        });
    });
    
    
    Type Color Wheels
    Car Red 4
    Motorcycle Green 2
    Bike Blue 2
    Car Blue 4
    Bike Green 2
    Motorcycle Red 2

    Stores the text from current td, hides tr nodes which do not contain the text.

提交回复
热议问题