1

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"

enter image description here

I would like something like :

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

1 Answer 1

3

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');

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.