replace() で同じ要素内で複数組のテキストを置換 同じ要素内で複数のテキストを変換したい場合のサンプルです。 <script src="./jquery.min.js"></script> <script> $(document).ready(function(){ $('.replace').each(function(){ var txt = $(this).html(); $(this).html(txt .replace(/A/g,'B') .replace(/C/g,'D') .replace(/E/g,'F') ); }); }); </script> 出力結果ですが、元のテキストはこちら。
![[JS]replace()を使って複数組の文字列を置換する方法 | WEBデザインのTIPSまとめサイト「ウェブネタチョ」](https://cdn-ak-scissors.b.st-hatena.com/image/square/b4e0e31ca5b350d8a33d010a2f646b91d1a82819/height=288;version=1;width=512/https%3A%2F%2Fwebantena.net%2Fwp-content%2Fuploads%2F2015%2F07%2F4334506.jpg)