1

I can't seem to figure this out. I have the code below in my web page, how do I change the "Click here" to blue or some color using jQuery?

<td width="30%" valign="top" align="left" 
class="td-label-276-7365 td-label-276 labeltext" 
id="td-label-field-7365">Flavors [Click here] :
</td>

Thank you in advance.

4 Answers 4

3

If you only want to change the color of "Click here" and you absolutely must use JS, then you can do:

var text = $('td').text();
text = text.replace(/\[Click\shere\]/g, '[<font color="blue">Click here</font>]');
$('td').html(text);

But it is more advisable to just do it directly with html and css, like:

<td width="30%" ...>Flavors [<span class="blue">Click here</span>] :</td>

and in your CSS:

span.blue {
   color: blue;
}

Demo: Both approaches can be seen here

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

4 Comments

Hi Techfoobar and thank you - the app is an autogen php app for various clients so I can't stick this html in like this, so I wanted to added some jquery to specific account changes.
Ahh, ok. In that case, the first option should suit your need.
question: I got a very weird output when i added this, but I see this does a replace, but shouldn't there be a find or search because this is a long form with several labels and fields. What I think it is doing is finding the text in every <td>
Yes, the 'td' selector in my answer above is just a placeholder. You will need to replace that with your TD's class or id. For example: $('td#td-label-field-7365')
1

use css()

 $('#td-label-field-7365').css('color','blue');

updated

if you need to change color just in [Click here], thn ad span around it and use css()

html

<td width="30%" valign="top" align="left" 
class="td-label-276-7365 td-label-276 labeltext" 
id="td-label-field-7365">Flavors <span>[Click here]</span>
</td>

jquery

$('#td-label-field-7365 span').css('color','blue');

3 Comments

but I need to change some specific text, not all the text within the #td.
Hi bipen - because this app is an autogen php app for various clients, I can't stick html/css in like this, but I see your principle. Thank you.
sure.. welcome... if cannot modify the HTML then.. replace is the best way... and with replace, i think @techfoobar has done it... anyways.. cheers ..:)
0
$('#td-label-field-7365').css('color', 'blue');

1 Comment

You missed the #. This will look for any tags called td-label-field-7365 like it would look for div's if you put 'div'
-1
$('.labeltext').css('color','blue');

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.