Reputation: 64834
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 .class - replace them with $$$$$
I'm using jQuery..
thanks
Upvotes: 0
Views: 291
Reputation: 236022
var str = $('.class').text();
str = str.replace(/####/g, '$$$$$');
$('.class').html(str);
Upvotes: 1
Reputation: 196002
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..
Upvotes: 0
Reputation: 53940
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)
})
Upvotes: 0