Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to replace more than once?

This is my code so far:

$("h1.intro:contains('|')").each(function() {
    $(this).html($(this).html().replace('|','</span><br /><span>')) 
});

This works just once, but it has to work for all of those "|"...

any ideas?

like image 413
Thomas Avatar asked Oct 19 '10 18:10

Thomas


Video Answer


1 Answers

Add /g modifier:

$("h1.intro:contains('|')").each(function() {
    $(this).html($(this).html().replace(/\|/g, '</span><br /><span>'));
});

More Info:

The g modifier is used to perform a global match (find all matches rather than stopping after the first match).

  • http://www.w3schools.com/jsref/jsref_regexp_g.asp
like image 168
Sarfraz Avatar answered Oct 04 '22 02:10

Sarfraz