admin管理员组

文章数量:1320915

I would like to have a "Load More" button that displays all the content of a div tag when clicked. It's important that all external resources within this content (such as images, JavaScripts, iframes, etc.) are fetched by the browser not immediately on each page load, but only after the user clicks the button.

I believe this can be achieved by first removing the content div from the DOM and then adding it back on button click, but I am not sure how to do that. Can someone please help me? Thank you!

I'd like to mention that the content div can be quite large (several kilobytes), so it needs to be located in the HTML code (as shown in the code below), rather than in the JS code. It will also be dynamic, constantly changing.

Alex

function load_more() {
  document.getElementById('content_div').style.display = 'block';
}
<html>
  <body>
    Content here...<br><br>
    <div style='display: inline-block; border: 1px solid black; padding: 10px; cursor: pointer' onclick='load_more()'>Load More</div><br><br>
    <div id='content_div' style='display: none'>
      More dynamic content here, including external images, scripts, and even iframes. These should NOT be automatically retrieved by the browser immediately on each page load, as they currently are with this code alone. Instead, they should only be fetched after the button above is pressed. So, if the user loads the page but does NOT click the button, no external resources will be retrieved by the browser.
    </div>
  </body>
</html>

本文标签: javascriptLoad external resources only on button clickStack Overflow