jquery - Checking if div is already added/open before prepend? -


i trying build menu/content solution click on menu-link adds new div main content , loads child html. im using .prepend newly opened content loads @ top of div pushing other content further down.

    $('#testappend').click(function(event){         event.preventdefault();         $('#maincontent').prepend( "<div id='testcontent1' style='display: none; float:left; padding:15px; width:100%;'></div>" );         $('#testcontent1').load("testhtml");         $('#testcontent1').show();  

but if click same link many times don't want stack same div many times need method check if div loaded , maybe scroll one/or place @ top again. i'm still new jquery , i'm thinking doing variable (boolean?). or better way?

thanks!

three different ideas you, each should work i've edited 1 of them:

if ($("#mydivid").load()) {   run code want run after element has been loaded } 

edit: better yet:

if ($("#mydivid").length) {   return; } 

or variation of .length one:

if (!$("#mydivid").length) {   run code want run after element has been loaded } 

Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

android - Keyboard hides my half of edit-text and button below it even in scroll view -

css - Make div keyboard-scrollable in jQuery Mobile? -