pal
pal

Reputation: 1242

Substring html tag using Javascript

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

Answers (3)

Blazemonger
Blazemonger

Reputation: 92913

It's not widely recognized that .html accepts a callback function:

$('.datatableheader').html(function(i,old) {
    return old.replace(/, ?/g, '');
});​

http://jsfiddle.net/3fBY4/1/

Upvotes: 1

FrontEnd Expert
FrontEnd Expert

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

Royi Namir
Royi Namir

Reputation: 148534

$(".datatableheader").html ($(".datatableheader").html().replace(",",""));

Upvotes: 2

Related Questions