tags:

views:

30

answers:

1
$(document).ready(function() {
  $('.taskStatus').text(function(n, oldcontent) {
     if (oldcontent == "Done") return "<a href='blah.com'>Click Here</a>";
  });
}); 


<span id="taskStatus_34" class="taskStatus">Done</span>

Why does the above code display the following on my webpage

Screenshot below:

alt text

Browser: Chrome 6.0.472.55 jQuery: 1.4.1

Edit: Apparently, it works for p (paragraph) tags, but not for divs and spans.

Edit: Using mcgrailm's answer, I ended up using the following code:

$('.taskStatus').each(function() {
  if ($(this).text() == 'Done') $(this).html("<a href='blah.com'>Click Here</a>"); 
});
A: 

because the text() expects a string

so you could do

   $('.taskStatus').each(function(){
    if($(this).text()== 'Done')  $(this).text("<a href='blah.com'>Click Here</a>");
   });

EDIT

you should change this line

 if (oldcontent == "Done") return "<a href='blah.com'>Click Here</a>";

to

if (oldcontent == "Done") return '<a href="blah.com">Click Here</a>'
mcgrailm
I thought the code was self explanatory. If the old content is "Done" then I want to replace it with a link.
jinsungy
According to http://api.jquery.com/text/, it also takes a function.
recursive
sorry I didn't read the whole thing
mcgrailm
huh did see that when I looked there first
mcgrailm
To mcgrailm's credit, I ended up using the .each function and setting the .html property. Thanks.
jinsungy
interestingly I copied your original code and pasted into page on my server and it worked fine
mcgrailm
That is quite odd. Well, thanks for your help.
jinsungy
your welcome, glad I could help
mcgrailm