简体   繁体   中英

how to highlight only one table td on click

Hello i have a table and i want to highlight table td when i click it. I managed to make it work but only on half. It change's the td when i select another but only on that row, what i want is to select only 1 td. Here is my js code

<script>
        $(".table").on("click", "td", function() {      
             $(this).closest("td").siblings().removeClass("td_select"); 
             $(this).toggleClass("td_select"); 
             $("#basicModal").modal("show");
       });

</script>

jsfiddle

If I got you correctly, you need this:

 $(this).closest("table").find('td').removeClass("td_select"); 
 //in the current table, find all cells, and remove the highlight

DEMO: https://jsfiddle.net/d3umm7w8/2/

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