Reputation: 11
This is to tricky for me,..
..here we go. I have a <table>
like this:
<table>
<tr>
<td class="cell0">01720007663795101</td>
</tr>
</table>
Now i would like to create a link arround the Text in the <td>
like this:
<a href="https://tracking.dpd.de/cgi-bin/delistrack?pknr=01720007663795101&typ=1&lang=de">01720007663795101</a>
so you can see there are 4 steps to do.
<td>
by classname<a href="https://tracking.dpd.de/cgi-bin/delistrack?pknr=
<td>
after <a href="https://tracking.dpd.de/cgi-bin/delistrack?pknr=
&typ=1&lang=de">
after <a href="https://tracking.dpd.de/cgi-bin/delistrack?pknr=01720007663795101
Upvotes: 1
Views: 1922
Reputation: 3262
var className = 'cell0';
td = $('td.' + className);
var link = '<a href="https://tracking.dpd.de/cgi-bin/delistrack?pknr=' + td.text() + '&typ=1&lang=de">' + td.text() + '</a>';
td.html(link);
See JsFiddle -> update JsFiddle
Upvotes: 2
Reputation: 6406
$('.cell0').each(function(index, element){
var tn = $(element).text();
$(element).html('<a href="https://tracking.dpd.de/cgi-bin/delistrack?pknr='+tn+'&typ=1&lang=de">'+tn+'</a>');
});
Or, shorter: http://jsfiddle.net/YuK6y/1/
$('.cell0').each(function(index, element){
$(element).wrapInner('<a href="https://tracking.dpd.de/cgi-bin/delistrack?pknr='+$(element).text()+'&typ=1&lang=de" />');
});
Upvotes: 3