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..
精彩评论