funkyeah
funkyeah

Reputation: 3194

How to manipulate a non-DOM jQuery object

I have a text string with HTML embedded in it. It also has CRs and/or newlines as well as tabs. I convert it into a jQuery object by passing it to to jQuery:

var htmlJqueryObj = jQuery(mystring);

Now I want to select and manipulate stuff within it via jQuery:

var modJqueryObj = jQuery("#"+buttonsParentID,htmlJqueryObj).clone().insertAfter(jQuery("#"+buttonsParentID,htmlJqueryObj));

however the above just returns a clone of the selected elements, while I would like it to insert a clone of the selected elements after those elements and return the the original jQuery object with the modified content.

Ideas?

Upvotes: 1

Views: 665

Answers (1)

Razor
Razor

Reputation: 29668

jQuery end() ftw:

var modJqueryObj =
    jQuery("#"+buttonsParentID,htmlJqueryObj)
        .clone()
             .insertAfter(jQuery("#"+buttonsParentID,htmlJqueryObj))
        .end()
    .end();

Upvotes: 2

Related Questions