I need a jQuery script that can change color on all td if it contain a onClick that contain “BG5”.
It need to work on IE7. I have tried $(“a:contains(‘BG5’)”).css(“background”,”#F6CED8″);
Is this possible?
They TD get the effect by a push on buttom
<tr bgcolor='#F2F2F2'>
<td>2011-04-18</td>
<td>a</td>
<td>a</td>
<td align="center"><a href="#" onClick="edit('BG5')"><img src="../img/icon/skruenogle.png" border=0 alt="Delete corr"></A>
<td align="center"><a href="#" onClick="disregard('BG5')"><img class="click" src="../img/icon/redcross.png" border=0 alt="Delete corr"></A></td>
</tr>
<tr bgcolor='#FFFFFF'>
<td>2011-04-18</td>
<td>a</td>
<td>a</td>
<td align="center"><a href="#" onClick="edit('1A1')"><img src="../img/icon/skruenogle.png" border=0 alt="Delete corr"></A>
<td align="center"><a href="#" onClick="disregard('1A1')"><img class="click" src="../img/icon/redcross.png" border=0 alt="Delete corr"></A></td>
</tr>
If I’ve understood you correctly, what you’re trying to do is change the background colour of every
trelement that contains anatag which has the string “BG5” in an attribute namedonClick.If that’s along the right lines, try something like this:
Here’s a working example using your HTML and the above jQuery. Basically what that does is get all the
aelements, filter them so we are left with only those which contain the string “BG5” in theonClickattribute, gets the closesttrelement to those, and sets the background colour.An important thing to note would be that the
attrmethod is case sensitive, so you’ll want to make sure you are consistent with your HTML!On a separate note, you really shouldn’t be using the
bgcolorattribute, as it’s deprecated. CSS should always be used instead. Also, there’s a couple oftdelements which have not been closed in the code in your question. That may just be a typo in the question, but worth a mention just in case!