I have a scenario where I need to find all <td>
containing the text "Status: Full" within a table that has been created using a javascript function.
The page <head>
contains the script that generates the markup for the event calendar. This script looks like this (I have removed the rest of the events for illustration purposes):
var today = new Date();
loaded('calendarEvents', 'start', today.getFullYear(), '6', '/9#20110716 Saturday 16 July 2011. Academic Only. Status: Full/10#20110730 Saturday 30 July 2011. Academic and General Training. Status: Available/11#20110813 Saturday 13 August 2011. ');
The generated HTML for a td containing my text looks like this:
<td class="linkbg" align="center">
<b>
<span onclick="selDate = 20110625; isDate(25,5,2011,22);return false;" title=" Saturday 25 June 2011. Academic and General Training. Status: Full" style="cursor:pointer;color:#FFFFFF">25</span>
</b>
</td>
It turns out that I have to locate each <td><b><span>
in this table that contains the text "Status: Full" and set the background color of that <td>
to be red.
I thought that doing something like this on page load would have allowed me to find these <td>
s but 开发者_开发百科this is unfortunately not the case (obviously this was within a $(document).ready();
:
$('td span[title*="Status: Full"]').parent().addClass("fullclass");
Can anyone shed some light on how I might achieve this?
Thanks, Tristan
:contains
only works for text inside the element, not on attributes of the element.
So you need to use the attribute based selectors. Try $('td span[onclick*="Status: Full"]')
The Status: Full
content is an attribute, not element content, so the :contains
selector won't work. You could do an attribute match:
$('td span[title*="Status: Full"]').parent().addClass("fullclass");
精彩评论