LoginSignup
2

More than 5 years have passed since last update.

【jQuery】BODY内の特定の文字列を置換する方法

Last updated at Posted at 2016-09-08

jQueryでBODY内の特定の文字列を置換する方法について紹介します。

次のように記述します。

$(function(){
    $('.クラス名').each(function(){
        var txt= $(this).html();
        $(this).html(txt.replace('変更前の文字列','変更後の文字列'));
    });
});

replace関数の引数には正規表現も使えます。
詳しくはJavaScriptの仕様を確認しましょう。
javascrit replace - Google 検索

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2