My first time posting here - I sincerely apologize for the messy formatting - I promise to get that figured out for next time!
The DOM contains a div element that looks like this:
<div id="maincontent"></div>
Its contents get setup as the program executes.
Later in the program, the div element’s innerHTML is stored in a variable as a string:
docContentStored = document.getElementById("maincontent").innerHTML;
console.log("docContentStored type: ", typeof docContentStored);
console.log("docContentStored: ", docContentStored);
/* RESULT:
docContentStored type: string
docContentStored: <ol><li><button type="button" class="collapsible" style="display: block; background: rgb(50, 50, 50); color: rgb(0, 255, 25);"><p class="labelbuttons">Chapter One</p></button><div class="panelcontent" style="background: rgb(0, 0, 0); color: rgb(0, 255, 255); display: none;"><p>This little piggy went to market.</p><p>This little piggy stayed home.</p><p>This little piggy ate roast beef.</p><p>This little piggy ate none.</p><p>This little piggy cried wee-wee-wee-wee-wee-wee all the way home!</p></div></li><li><button type="button" class="collapsible active" style="display: block; background: rgb(50, 50, 50); color: rgb(0, 255, 25);"><p class="labelbuttons">Chapter Two</p></button><div class="panelcontent" style="background: rgb(0, 0, 0); color: rgb(0, 255, 255); display: block;"><p>One for the money.</p><p>Two to let go.</p><p>Three to get ready.</p><p>Four to GO!</p></div></li><li><button type="button" class="collapsible" style="display: block; background: rgb(50, 50, 50); color: rgb(0, 255, 25);"><p class="labelbuttons">Chapter Three</p></button><div class="panelcontent" style="background: rgb(0, 0, 0); color: rgb(0, 255, 255); display: none;"><p>And, there you have it.</p><p>The END.</p></div></li></ol>
*/
The list items contain a button element followed by a div element (class panelcontent).
The second list item contains a panelcontent div item where the style attribute includes “display: block”.
However, when I try to restore it, for some reason, that second list item panelcontent comes out with “display: none” and I have verified that the variable still shows “display: block”.
console.log("restored docContentStored: ", docContentStored);
document.getElementById("maincontent").innerHTML = docContentStored;
console.log("received docContentStored: ", document.getElementById("maincontent"));
/* RESULT:
restored docContentStored: <ol><li><button type="button" class="collapsible" style="display: block; background: rgb(50, 50, 50); color: rgb(0, 255, 25);"><p class="labelbuttons">Chapter One</p></button><div class="panelcontent" style="background: rgb(0, 0, 0); color: rgb(0, 255, 255); display: none;"><p>This little piggy went to market.</p><p>This little piggy stayed home.</p><p>This little piggy ate roast beef.</p><p>This little piggy ate none.</p><p>This little piggy cried wee-wee-wee-wee-wee-wee all the way home!</p></div></li><li><button type="button" class="collapsible active" style="display: block; background: rgb(50, 50, 50); color: rgb(0, 255, 25);"><p class="labelbuttons">Chapter Two</p></button><div class="panelcontent" style="background: rgb(0, 0, 0); color: rgb(0, 255, 255); display: block;"><p>One for the money.</p><p>Two to let go.</p><p>Three to get ready.</p><p>Four to GO!</p></div></li><li><button type="button" class="collapsible" style="display: block; background: rgb(50, 50, 50); color: rgb(0, 255, 25);"><p class="labelbuttons">Chapter Three</p></button><div class="panelcontent" style="background: rgb(0, 0, 0); color: rgb(0, 255, 255); display: none;"><p>And, there you have it.</p><p>The END.</p></div></li></ol>
received docContentStored:
<div id="maincontent">
<ol>
<li>
<button type="button" class="collapsible active" style="display: block; background: rgb(50, 50, 50); color: rgb(0, 255, 25);">
<p class="labelbuttons">Chapter One</p>
</button>
<div class="panelcontent" style="background: rgb(0, 0, 0); color: rgb(0, 255, 255); display: none;">
<p>This little piggy went to market.</p>
<p>This little piggy stayed home.</p>
<p>This little piggy ate roast beef.</p>
<p>This little piggy ate none.</p>
<p>This little piggy cried wee-wee-wee-wee-wee-wee all the way home!</p>
</div>
</li>
<li>
<button type="button" class="collapsible active" style="display: block; background: rgb(50, 50, 50); color: rgb(0, 255, 25);">
<p class="labelbuttons">Chapter Two</p>
</button>
<div class="panelcontent" style="background: rgb(0, 0, 0); color: rgb(0, 255, 255); display: none;">
<p>One for the money.</p>
<p>Two to let go.</p><p>Three to get ready.</p>
<p>Four to GO!</p>
</div>
</li>
<li>
<button type="button" class="collapsible active" style="display: block; background: rgb(50, 50, 50); color: rgb(0, 255, 25);">
<p class="labelbuttons">Chapter Three</p>
</button>
<div class="panelcontent" style="background: rgb(0, 0, 0); color: rgb(0, 255, 255); display: none;">
<p>And, there you have it.</p>
<p>The END.</p>
</div>
</li>
</ol>
</div>
*/
So while the docContentStored variable still shows the panelcontent of the second with “display: block”, when assigned to the innerHTML of the maincontent div element, it comes out with “display: none” and I do not know why.
I have tried removing the linefeeds with .replace(/\r|\n|\r\n/, “”) and I have tried .trim(), but the result is the same.
The final result will have many tags and some will have the display set to none while others set to block and I need the restore of it to match what was backed up. How do I accomplish this?