jQuery: replace() in html()

前端 未结 3 866
臣服心动
臣服心动 2021-01-05 13:23

How can I replace html parts with replace()?


         


        
3条回答
  •  旧巷少年郎
    2021-01-05 13:25

    Make your pattern global by using the g switch:

    var e = $("div"),
    fix = e.html().replace(/google.com/g, "duckduckgo.com");
    e.html(fix);
    

    jsFiddle example

    This way it replaces the link and the text.

提交回复
热议问题