Given the table below
+-----------------------+-----------------+---------------+
| 212 | fred | red |
+-----------------------+-----------------+---------------+
| 230 | Tom | blue |
+-----------------------+-----------------+---------------+
| 240 | Bob | green |
+-----------------------+-----------------+---------------+
| 253 | Jim | grey |
+-----------------------+-----------------+---------------+
I am trying to highlight a row using the following without success.
var userid = 212;
$('tr').find('td:eq(0):contains('+userid+')').parent().css('backgroundColor', 'yellow');
Which is obviously wrong as it doesn’t work. Where am I going wrong?
EDIT: So I cut and pasted the exact table from my page and it works in jsfiddle as well. what I haven’t said is I have a parent page, click a button and the table loads. Click buttons within the table and it loads the highlight button. The code above is actually on the parent page. Somehow it can’t ‘see’ the table?
Are you putting that function inside a DOM-ready call. So it fires once the DOM is ready? (Wow, that was repetitive) I just tried it on jsFiddle and it works fine
See here
You need something like