Highlighting columns in a table with jQuery

后端 未结 6 1916
感动是毒
感动是毒 2021-01-16 02:02

I have a table and I am highlighting alternate columns in the table using jquery

$(\"table.Table22 tr td:nth-child(even)\").css(\"background\",\"blue\");
         


        
6条回答
  •  失恋的感觉
    2021-01-16 02:55

    Here is some code I used to do nested checkbox highlighting within a table. I needed to be able to do a "check all/uncheck all" but only within at a single level within the nesting; that is, I didn't want child elements getting selected as well.

    var parentTable = $(this).parents("table:first");
    var exclusions = parentTable.find("table :checkbox.select");
    var checkboxes = parentTable.find(":checkbox.select").not(exclusions);
    

    I'd get the first table above the current one I was in, get all the checkboxes below this newly found parent table, then exclude them from the complete list of checkboxes I could find. Basically, I was finding every checkbox, but then excluding any child checkboxes I found.

    The same could be adapted in your case; replace the checkbox selection with columns instead.

提交回复
热议问题