Reputation: 1
I have a main page call "main.html". Inside the main page, there is a table. Then I created a page call "newPage.html"
The table is in the following format.
<table width="707" border="0">
<tr>
<td class="link">Change this to hyperlink</td>
<td></td>
<td></td>
</tr>
</table>
How can I use JQuery to change the text "Change this to hyperlink" to a clickable link, linking it to the page "newPage.html"?
So when I click "Change this to hyperlink", I will be redirected to "newPage.html".
All the files is already in the same folder. I am putting the script in a new .js file.
Thank you in advance.
Upvotes: 0
Views: 331
Reputation: 188
var text = $('.link').text();
$('.link').html('<a href="file.php">' + text + '</a>');
Upvotes: 0
Reputation: 207861
$(function () {
$('.link').html(function () {
return '<a href="newPage.html">' + $(this).text() + '</a>';
})
});
Upvotes: 1