简体   繁体   中英

Load internal div after clicking button

I have an invisible div by display: none .

I need to load div after clicking on button, not OnPageLoad.

Notice :

I said LOAD div after Clicking button, i'm not talking about SHOW div.

I don't want load div on page load.

HTML is here :

<input id="btn" type="button" value="Load Div" />
<div class="content" style="display: none;">
    <img src="http://www.kippaxvet.com.au/Portals/kippaxvet/cute%20pup.jpg" />
</div>

How can i do that ?

Any ideas would be appreciated.


EDIT {More information} :

I have a div with many elements and images in there.

If i load that div onPageLoad it's very heavy and take long times.

I just need to Load that div when the user want show it up.

try this:

<input id="btn" type="button" value="Load Div" onclick="load()"/>

function load()
{
  var imgDiv = document.createElement('div');
  $(imgDiv ).addClass('content');
  $(imgDiv).append('<img id="dynamicImg" src="http://www.kippaxvet.com.au/Portals/kippaxvet/cute%20pup.jpg" />')
  // add the imgDiv to your parent container element. 
  // for e.g. $("#container").append(imgDiv)
}

JsFiddle : http://jsfiddle.net/vendettamit/QB8Hv/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM