开发者

how to replace specific strings in HTML docs or specific elements?

开发者 https://www.devze.com 2022-12-26 18:27 出处:网络
How can I parse a html document or just a html element in order to replace all specific strings into other ones ?

How can I parse a html document or just a html element in order to replace all specific strings into other ones ?

In other terms: - search for all strings #### in element .cla开发者_Python百科ss - replace them with $$$$$

I'm using jQuery..

thanks


var str = $('.class').text();
str = str.replace(/####/g, '$$$$$');
$('.class').html(str);


This is how you replace one class with another

$(".foo").addClass("bar").removeClass("foo")

or are you looking for a way to replace inside text nodes?

$("#something").find("*").andSelf().contents().each(function() {
    if(this.nodeType == 3)
        this.nodeValue = this.nodeValue.split(search).join(replace)
})


Have a look at the string replace method of javascript for the actual replacing, and look at the html() and text() method of jquery on accessing the contents of a specific element..

0

精彩评论

暂无评论...
验证码 换一张
取 消