Adrian
Adrian

Reputation: 3052

How to use jQuery to remove multiple texts inside div?

I have search results and they are concatenated with multiple words at the beginning of the sentence.

<div itemprop="articleSection" class="entry-summary">
WHAT WE DOSource Integrate Support Manage Transform A metre-wide “lazy river” of cobblestones meanders through the clay-paved plaza fronting Australia’s newest international-standard swim centre.
</div>

I want to remove the words "WHAT WE DOSource Integrate Support Manage Transform" from the beginning of EACH class="entry-summary"

Thanks!

Upvotes: 0

Views: 164

Answers (4)

Lu&#237;s P. A.
Lu&#237;s P. A.

Reputation: 9739

You can use this jQuery

jQuery

$('.entry-summary').each(function() {
    var text = $(this).text();
    $(this).text(text.replace('WHAT WE DOSource Integrate Support Manage Transform', '')); 
});

DEMO HERE

Upvotes: 2

A. Wolff
A. Wolff

Reputation: 74420

You could just split it:

$('.entry-summary:contains("Transform ")').text(function(_, txt){
    return txt.split('Transform ')[1];
});

Upvotes: 0

Manish Rane
Manish Rane

Reputation: 579

You can Use str_replace function.

var str = $(".entry-summary").html(); 
var res = str.replace("WHAT WE DOSource Integrate Support Manage Transform", "");
$(".entry-summary").html(res);

Upvotes: 0

Felix Kling
Felix Kling

Reputation: 816384

Use the .text method to change the text:

$('.entry-summary').text(function(index, value) {
  return value.replace(
    /^\s*WHAT WE DOSource Integrate Support Manage Transform/,
    ''
  );
});  

Upvotes: 1

Related Questions