tags:

views:

21

answers:

2

I'm doing a $.get() request which returns some HTML. I would like to manipulate that html before I'm adding it to the DOM (make it hidden).

Can I do this without adding it to a behind-the-scene node, manipulate it and finally add it to the destination node?

+2  A: 

Use something like this:

newHtml = $.get();
wrappedSet = $(newHtml);

You now have a wrapped set of your new html, which you can manipulate using standard jQuery methods.

kgiannakakis
Are you sure you don't just mean $(newHtml)?
samjudson
You are right, I've corrected it.
kgiannakakis
yes, indeed. I changed the syntax without the quotes and it works exactly as I wanted. thanks :)
borisCallens
A: 

Yup, you can.

$.get(url, function(html) { var $myDOMObjects = $(html);

// manipulate to your heart's content

$('body').append($myDomObjects);

});

Cheers,

jrh

Here Be Wolves