I have an HTML document that I receive from the server via an Ajax call and I obviously receive that HTML document as a string :
var serverResponse = "<html><head>.......";
I now want to alter parts of this HTML document and then send it back to the server as an HTML string.
Changes include adding/editing attributes and their values (e.g. style="", src="", href="") as well as changing some innerHTML etc..
There are two ways of achieving this :
No.1 : I can either loop through the whole string and apply some elaborate regex every time in order to find the value I want and change it or add new values etc..
No.2 : I can go for the easiest solution which is converting that string into a jQuery object and then easily traverse that and change it.
I believe the 2nd option has the undesired side effect of actually loading files (like images or evens scripts), at least on some browsers (like IE ?). Please correct me if I'm wrong and if there's nothing to worry about then I'll just go for the 2nd option.
example :
I know I can do the following :
var $html = $(serverResponse);
(I know jQuery.parseHTML() does the same as the above..)
And then perform my changes by doing stuff like :
$html.find('.some-div').eq(2).css('background', 'url(http://some-new/img.jpg)');
Once I'm done with the changes I then need to convert the updated HTML back into a string and post it back to the server.
Do you have any suggestions ?
src=todata-src=or something. then when you're ready to load them, do the inverted operation.