Simple javascript find and replace

后端 未结 6 1073
我在风中等你
我在风中等你 2020-12-16 03:07

is there a straightforward method for searching within a div for a specific string and replacing it with another? I cannot use .replaceWith alone because there are other ele

6条回答
  •  遥遥无期
    2020-12-16 03:53

    Try this:

    var foo = $('#foo').html();
    
    foo = foo.replace('this string', 'this other string');
    
    $('#foo').html(foo);
    

    Fiddle: http://jsfiddle.net/maniator/w9GzF/

提交回复
热议问题