Friends,
I have a simple page. I have a div (let's call it #content) which contains content (in html) that I want to store into a variable.
<div id="content">
<div id="left">
<h1>Cool title</h1>
<p>text</p>
</div>
<div id="right">
<p>more text</p>
</div>
</div>
I then have a div which is binded to a click function through JQuery. When clicked, it stores the content of #content into a variable, storedHTML, and the height to storedHeight. It then sets the height of #content to 0 and deletes the html within #content.
Then when clicked again it animates the height back to the storedHeight, let's say 200px; it also reloads the html back into the div.
The problem lies in reloading the html into the div. How do I go about doing this? I've tried:
storedHTML = $('#content').html(); //to store it
$('#content').html(''); //to clear it
$('#content').html(storedHTML); //to load it back up again
tries to load it...but to no avail.
This worked perfectly when I first wrote it to grab text from a p tag, minimize it, and then enlarge it back up again. E.g.:
storedText = $('p#example').text(); //to store it
$('p#example').text(''); //to clear it
$('p#example').text(storedText) //to load it back up again
For the purpose of this html load, I have tried using .html(), .text(), .data(), .load(). and a combination of .html() and .append()
I'm clearly failing. I can't figure out how to load html (multiple divs and such) back into this div. I would love to learn the proper way to do this!
Thank you kindly for all your continued help friends.