jQuery Select first and second td

后端 未结 7 1369
南旧
南旧 2020-12-05 04:21

How can I add a class to the first and second td in each tr?

THIS ONE
7条回答
  •  天命终不由人
    2020-12-05 04:40

    If you want to add a class to the first and second td you can use .each() and slice()

    $(".location table tbody tr").each(function(){
        $(this).find("td").slice(0, 2).addClass("black");
    });
    

    Example on jsfiddle

提交回复
热议问题