1

I have this html-table:

<table id=mytable> <tr> <td> Mark </td> <td> Susan </td> </tr> </table> 

Somewhere from javascript an event occur and I can will be able to fetch the name, which is one of those in the table. From javascript/jquery I need to find the td-element containing the name and color it. I tried with:

$("#mytable").find("td:contains('Mark')").parent().css('background-color', 'red'); 

But the td-element doesnt get colored.

2 Answers 2

1

I believe you need to try this:

$("#mytable").find("td:contains('Mark')").css('background-color', 'red');

DEMO

OR

$("#mytable td:contains('Mark')").css('background-color', 'red');

DEMO

Sign up to request clarification or add additional context in comments.

Comments

0

You already selected the td what you did is you tried to add a color to the tr which is the parent of the selected td:

$("#mytable").find("td:contains('Mark')").css('background-color', 'red'); 

that's why you example should be highlighting both td as the color applied for the tr

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.