Louis
Louis

Reputation: 2608

jquery .each() to replace all alements that have a class with regex

I want to the replace the html content of all instances of a class, with a regex :

$('ul#chosenmodel-menu').find("a.ui-link-inherit:contains(SMALL-WAVE)").each().html(function(idx,oldHtml){
    return oldHtml.replace(/SMALL/, "blablablablabla");
});

but it doesn't work.

Upvotes: 0

Views: 28

Answers (2)

Milind Anantwar
Milind Anantwar

Reputation: 82231

Try this:

$('ul#chosenmodel-menu').find("a.ui-link-inherit:contains(SMALL-WAVE)").each(function(){
  $(this).html($(this).html().replace(/SMALL/, "blablablablabla"));
});

Upvotes: 0

Rajaprabhu Aravindasamy
Rajaprabhu Aravindasamy

Reputation: 67207

Try to remove that .each() it wont need here,

$('ul#chosenmodel-menu').find("a.ui-link-inherit:contains(SMALL-WAVE)").html(function(idx,oldHtml){
    return oldHtml.replace(/SMALL/, "blablablablabla");
});

Upvotes: 1

Related Questions