Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTML Replace Script only replacing first term

Tags:

jquery

replace

I have this script running on a Japanese directory, working to replace English terms on the page for a Blog add-on for the terms that were not customizable. It works great but it only seems to replace the term the first time it sees it.

http://www.martyregan.com/jp/blog/

For example you'll see View Post, Tags, Feb are still in English on the bottom Blog Post.

Here's the script:

$(document).ready(function(){
            $('#pb_sidebar, #left-sidebar-inner, #pb_body, #main-content-inner, #sidebar-archives').each(function(i){
$(this).html($(this).html().replace('Category List','ブログテーマ一覧'));
$(this).html($(this).html().replace('Tag List','タグ'));
})
    })

How can I alter it so that it grabs the term everywhere it sees it? Thanks!

like image 247
Joseph Thomas Avatar asked May 28 '26 23:05

Joseph Thomas


1 Answers

You need to use regex with the /g option that will repeat otherwise string.replace() only runs once.

For example:

$(this).html($(this).html().replace(/Category List/g,'ブログテーマ一覧'));
like image 54
Lloyd Avatar answered May 31 '26 14:05

Lloyd



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!