Reputation: 1242
I want to sub string and remove the ,
which appears within the span tag and display the name alone. Below are the two cases which needs to work.
Case1: <span class="datatableheader">No results found, </span>
Case2: <span class="datatableheader">Jude Gomes, </span>
A single function should help in removing the ,
in both cases and display the result as
<span class="datatableheader">No results found </span>
<span class="datatableheader">Jude Gomes </span>
Appreciate for any help.
Thanks
Upvotes: 1
Views: 723
Reputation: 92913
It's not widely recognized that .html
accepts a callback function:
$('.datatableheader').html(function(i,old) {
return old.replace(/, ?/g, '');
});
Upvotes: 1
Reputation: 5803
you can try this also
var parts = id.split(':'); //because u have case1: or case2:
// it will split into string in array//
$('#parts[1]').replace(",",""));
//try to print that it will work
nice question.
Upvotes: 0
Reputation: 148534
$(".datatableheader").html ($(".datatableheader").html().replace(",",""));
Upvotes: 2