简体   繁体   中英

Adding CSS style into specific line HTML table

I need to check if my HTML table contains a specific string (for example 'LA DEFENSE') and then color the current line by adding style="background-color: red"

在此处输入图像描述

I would like something like:

$("#colorline").click(function() {
       if ($('rejets_communes').contains('LA DEFENSE'){
              #color line by adding style element to the specific line
        }
 }) 

Here is a working fiddle.

<table id="myTable">
<tr>
  <td>LA DEFENSE</td>
  <td>SOMETHING ELSE</td>
</tr>
</table>

If you want to set the background color for the whole line you can use

$('#myTable').find("td:contains('LA DEFENSE')").parents("tr").css('background-color', 'red');

otherwise, use this

$('#myTable').find("td:contains('LA DEFENSE')").css('background-color', 'red');

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