Highlighting columns in a table with jQuery

后端 未结 6 1977
感动是毒
感动是毒 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:49

    Qualify it with the > descendant selector:

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

    You need the tbody qualifier too, as browsers automatically insert a tbody whether you have it in your markup or not.

    Edit: woops. Thanks Annan.

    Edit 2: stressed tbody.

提交回复
热议问题