jquery compatibility issues

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

following jquery code is working fine in firefox.

and not working in chrome and explorer


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

what i have to change for working in all browsers

Regards

Baiju




Responses

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

Up
0
Down
Hi,
Try like this.
If you have any concerns,revert back. you have posted this issue already, right!
http://www.dotnetfunda.com/forums/show/18321/error-in-replace-function-in-jquery
Did you get the solution?

$("#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 (cellText.toUpperCase().indexOf('S')>=0) {
$(this).text(cellText.replace('S', ''));
$(this).css('background-color', 'Gainsboro');
}
});


Thank you,
Govind

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

Login to post response