Get a string representation of the whole DOM jquery HTML object

I had a little look around, and it is difficult for me to solve the problem associated with my problem.

I basically have an HTML string, I convert it to a JQuery DOM object so that I can easily remove all elements that have a specific class using JQuery.remove (). I.e.

var radHtml = editor.get_html(); var jqDom = $(radHtml); $(".thickbox", jqDom).remove(); $(".thickboxcontent", jqDom).remove(); editor.set_html(this.innerHTML); 

NOTE. HTML is derived from the content in the RADEditor text editor, so there are no parent HTML tags, so it may look like this:

 <p>This is a header</p> <p>this is some content followed by a table </p> <a href="#TB_inline?height=350&amp;width=400&amp;inlineId=myOnPageContent0" class="thickbox">Test Thickbox</a> <div id="myOnPageContent0" class="thickboxcontent"> <table class="modal"> <thead> </thead> <tbody> <tr> <td>item</td> <td>result</td> </tr> <tr> <td>item 1</td> <td>1</td> </tr> <tr> <td>item 2</td> <td>2</td> </tr> <tr> <td>item 3</td> <td>3</td> </tr> </tbody> </table> </div> 

Here is what jqDom.html () returns from the HTML above:

 "This is a header" 

I was wondering if there is an easy way to do this - to have some html and remove all elements (in this case divs) that have a specific class (but leave their contents). JQuery does not need to be used, but I would like to.

Manipulating the DOM object is fine - it gets the entire DOM object as a string, with which I had a problem.

Any help would be very helpful. Thanks.

+7
jquery dom
source share
2 answers
 var radHtml = editor.get_html(); var jqDom = $(radHtml); jqDom.wrap('div'); //dont remember if thats ok or u need to asign it in the jqDom again $(".thickbox", jqDom).remove(); $(".thickboxcontent", jqDom).remove(); editor.set_html(jqDom.html()); 

Maybe it will help

+1
source share

If you want the html of each matching element to be selected by your selector, try running map :

 var allHtmls = jqDom.find('.thickbox').map(function(){ return this.innerHTML; }); 

Also, it looks like you can use unwrap , which was added in jQuery 1.4+ ( http://api.jquery.com/unwrap/ )

jqDom.find('.thickbox').children().unwrap();

+5
source share

All Articles