error in replace function in jquery

Posted by Klbaiju under jQuery on 6/12/2014 | Points: 10 | Views : 482 | Status : [Member] | Replies : 1
Hi,

I want to use replace function in jquery

here is my code

$("#GridView1 tr td").filter(":not(td:first-child) ").each(function () {
var cellText = $(this).text();
if ((cellText).contains('M')) {
(cellText).replace('M', '');

$(this).css('background-color', 'Red');



}
});

background color is changing but charactar M is not replacing




Responses

Posted by: kgovindarao523-21772 on: 6/13/2014 [Member] [MVP] Bronze | Points: 25

Up
0
Down
Hi,
Try like this.

$("#GridView1 tr td").filter(":not(td:first-child) ").each(function () { 
var cellText = $(this).text();
if (cellText.toUpperCase().indexOf('M')>=0) {
/*this Replaces First occurance of M=> if you want replace in entire string use cellText.replace(/M/g, '') */
cellText.replace('M', '');
$(this).css('background-color', 'Red');
}
});

if it helps Please Mark as answer

Thank you,
Govind

Klbaiju, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response