Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery replace character with another

Tags:

jquery

Let's say I have:

<h1>Win $50<h1>

I need to change the $ sign to € with jQuery
So I can do it like that:

$('h1').text( $('h1').text().replace('$', '€') );

But what if I have something like that:

<h1>Win $50 and Get $100</h1>

It only change the first one, How can I change it all?

like image 743
user4571629 Avatar asked Dec 05 '22 22:12

user4571629


1 Answers

Use regexp with g flag

$('h1').text( $('h1').text().replace(/\$/g, '€') );
like image 149
RafH Avatar answered Jan 08 '23 12:01

RafH