0

I am using JQuery's html() method to get the HTML of a div on my page. However it is returning a string containing all the JQuery-generated code too:

<ul><li id="fact_1" class="jstree-open"><ins class="jstree-icon">&nbsp;</ins><a><ins class="jstree-icon">&nbsp;</ins>Factory 1: (1-1000)</a><ul id="fact_1_children"><li class="jstree-leaf"><ins class="jstree-icon">&nbsp;</ins>348</li><li class="jstree-leaf"><ins class="jstree-icon">&nbsp;</ins>813</li><li class="jstree-leaf"><ins class="jstree-icon">&nbsp;</ins>447</li><li class="jstree-leaf"><ins class="jstree-icon">&nbsp;</ins>112</li><li class="jstree-last jstree-leaf"><ins class="jstree-icon">&nbsp;</ins>277</li></ul></li><li id="fact_2" class="jstree-open"><ins class="jstree-icon">&nbsp;</ins><a><ins class="jstree-icon">&nbsp;</ins>Factory 2: (1001-2000)</a><ul id="fact_2_children"><li class="jstree-leaf"><ins class="jstree-icon">&nbsp;</ins>1833</li><li class="jstree-leaf"><ins class="jstree-icon">&nbsp;</ins>1142</li><li class="jstree-leaf"><ins class="jstree-icon">&nbsp;</ins>1038</li><li class="jstree-leaf"><ins class="jstree-icon">&nbsp;</ins>1245</li><li class="jstree-leaf"><ins class="jstree-icon">&nbsp;</ins>1891</li><li class="jstree-leaf"><ins class="jstree-icon">&nbsp;</ins>1532</li><li class="jstree-last jstree-leaf"><ins class="jstree-icon">&nbsp;</ins>1741</li></ul></li><li id="fact_3" class="jstree-open"><ins class="jstree-icon">&nbsp;</ins><a><ins class="jstree-icon">&nbsp;</ins>Factory 3: (2001-3000)</a><ul id="fact_3_children"><li class="jstree-leaf"><ins class="jstree-icon">&nbsp;</ins>2895</li><li class="jstree-leaf"><ins class="jstree-icon">&nbsp;</ins>2974</li><li class="jstree-leaf"><ins class="jstree-icon">&nbsp;</ins>2120</li><li class="jstree-leaf"><ins class="jstree-icon">&nbsp;</ins>2230</li><li class="jstree-leaf"><ins class="jstree-icon">&nbsp;</ins>2854</li><li class="jstree-last jstree-leaf"><ins class="jstree-icon">&nbsp;</ins>2413</li></ul></li><li id="fact_4" class="jstree-open"><ins class="jstree-icon">&nbsp;</ins><a><ins class="jstree-icon">&nbsp;</ins>Factory 4: (3001-4000)</a><ul id="fact_4_children"><li class="jstree-leaf"><ins class="jstree-icon">&nbsp;</ins>3495</li><li class="jstree-leaf"><ins class="jstree-icon">&nbsp;</ins>3951</li><li class="jstree-last jstree-leaf"><ins class="jstree-icon">&nbsp;</ins>3931</li></ul></li><li id="fact_5" class="jstree-open jstree-last"><ins class="jstree-icon">&nbsp;</ins><a><ins class="jstree-icon">&nbsp;</ins>Factory 5: (4001-5000)</a><ul id="fact_5_children"><li class="jstree-leaf"><ins class="jstree-icon">&nbsp;</ins>4969</li><li class="jstree-leaf"><ins class="jstree-icon">&nbsp;</ins>4645</li><li class="jstree-last jstree-leaf"><ins class="jstree-icon">&nbsp;</ins>4517</li></ul></li></ul>

I need to be getting a string containing only the raw HTML, like this:

<ul id="tree"><li id="fact_1" class="jstree-open"><a>Factory 1: (1-1000)</a><ul id="fact_1_children"><li>348</li><li>813</li><li>447</li><li>112</li><li>277</li></ul></li><li id="fact_2" class="jstree-open"><a>Factory 2: (1001-2000)</a><ul id="fact_2_children"><li>1833</li><li>1142</li><li>1038</li><li>1245</li><li>1891</li><li>1532</li><li>1741</li></ul></li><li id="fact_3" class="jstree-open"><a>Factory 3: (2001-3000)</a><ul id="fact_3_children"><li>2895</li><li>2974</li><li>2120</li><li>2230</li><li>2854</li><li>2413</li></ul></li><li id="fact_4" class="jstree-open"><a>Factory 4: (3001-4000)</a><ul id="fact_4_children"><li>3495</li><li>3951</li><li>3931</li></ul></li><li id="fact_5" class="jstree-open"><a>Factory 5: (4001-5000)</a><ul id="fact_5_children"><li>4969</li><li>4645</li><li>4517</li></ul></li></ul>

Is there any way to do this? This in advance.

1
  • No, once the DOM is modified, it is modified. Commented Dec 20, 2013 at 0:33

1 Answer 1

1

If you store the HTML, before its modified, to a var, you will have it for later.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, I just thought of this and am working on it now.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.