javascript - using JQuery can I replace an empty div with the result of a load event -


i have placeholder div nested inside div.
want replace placeholder div data returned .load() call when parent div clicked on using onclick function...

for example:

function accordianclick(projectid) {          $("#project-placeholder-" + projectid).replacewith(                $.load("projectdetail?projectid=" + projectid)); } 

the trick want fetch data loaded if placeholder div exists once click on parent , replace first time won't exist anymore therefore load function not called.

for example works every-time click parent div still fetches data.

function accordianclick(projectid) {     $.get("projectdetail?projectid=" + projectid, function(data) {         $("#project-placeholder-" + projectid).replacewith(data);     }, 'html'); } 

use length check if exists.

function accordianclick(projectid) {     var $container = $("#project-placeholder-" + projectid);     if( $container.length > 0 ) {         $.get("projectdetail?projectid=" + projectid, function(data) {             $container.replacewith(data);         }, 'html');     } } 

Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -