Reputation: 15
I have a simple question for jQuery...
I have a table with a link like this
<table>
<tr>
<td class="views-field">
<a href="ciao">201105</a>
</td>
</tr>
</table>
Now I would change the link's text from 201105 to 2011-05
(simple add a "-" after the first 4 characters)
I tried substring but don't work... Help me!!
Upvotes: 0
Views: 4731
Reputation: 9929
Try the code below, that should work fine.
var replaceElement = $("td.views-field a").first();
var oldDate = replaceElement.text();
var newDate = oldDate.substring(0, 4) + "-" + oldDate.substring(4,6);
replaceElement.text(newDate);
Upvotes: 0
Reputation: 652
$("a").text($("a").text().substring(0,4)+"-"+$("a").text().substring(4,6) );
Upvotes: 0
Reputation: 7035
This will translate all td.views-field links:
$('td.views-field a').each(function () {
var oldText = $(this).text();
$(this).text(oldText.substr(0,4) + '-' + oldText.substr(4));
});
Upvotes: 5