There's probably a better way, but you could do something like this:

$("td.data").each(function() {
   var t = $(this).text();
   $(this).html("<a href=''>" + t + "</a>");
});

-- Josh


----- Original Message ----- From: "jQuery(new).to(me)" <[EMAIL PROTECTED]>
To: "jQuery (English)" <[email protected]>
Sent: Thursday, January 03, 2008 3:43 PM
Subject: [jQuery] How can I add HTML tag from jQuery?



Hi,

Please give me an idea how to do this:
I want to add <a></a> to a table cell.
For example,
If I have the following table;

<table>
<tr><td class="data">Data1</td><td class="value">Value 1</td></tr>
<tr><td class="data">Data2</td><td class="value">Value 2</td></tr>
</table>

Now I want to add anchor to the "data" class, so that result would
look like this:

<table>
<tr><td class="data"><a href="">Data1</a></td><td class="value">Value
1</td></tr>
<tr><td class="data"><a href="">Data2</a></td><td class="value">Value
2</td></tr>
</table>

Now, with jQuery, all I can think of is
$(".data").text().wrap('<a></a>');

but unfortunately, this won't wok.
How can I do this w/jQuery?

thanks for your help in advance.

Reply via email to