Nani gandham
Nani gandham

Reputation: 11

How to replace text inside span inside anchor inside div in jquery

how to replace Sunday,Monday,Tuesday.. with SUN,MON,TUE... in the below table using JQuery. Any help would be appreciated.

<table> 
<tr>
<th><div> <div id="xyz"> <a href="www.google.com"> 20 may
<span>Sunday</span> </a> </div></div></th>
<th><div> <div id="xyz"> <a
href="www.google.com"> 21 may <span>Monday</span> </a> </div></div> </th>
<th><div> <div id="xyz"> <a href="www.google.com"> 22 may
<span>Tuesday</span> </a> </div> </div></th>
</tr>
</table>

By Nani

Upvotes: 0

Views: 836

Answers (1)

alex
alex

Reputation: 490263

This should do it.

var days = {
    'Sunday': 'SUN',
    'Monday': 'MON'
    /* ... */
};

$('span').text(function(i, day) {
    return days[day] || day;
});

If there is no match, it won't update the span.

Upvotes: 2

Related Questions