views:

45

answers:

3

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

A: 

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)
})
stereofrog
I think he wants to replace content text that resides inside element with a specific class (.class)
Gaby
+1  A: 
var str = $('.class').text();
str = str.replace(/####/g, '$$$$$');
$('.class').html(str);

Kind Regards

--Andy

jAndy
A: 

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..

Gaby