jquery - Check if variable have already been appended -


got problem. in following fiddle have tried exemplify how wish check if variable "htmlstring" has been appended, , if so, not append another. on other hand if haven't been appended, ofcourse append it.

http://jsfiddle.net/lc5gdvge/6/

how make work? in all, need if-else code, check previous appended variable. if none has been appended append, if container contains appended variable "htmlstring" ofcourse shouldn't append new one.

 $(document).ready(function () { $('.outerdiv').click(function () {     var htmlstring = $(this).contents().filter(function(){return this.nodetype == 3;}).text()     if ($('.innerdiv').innerhtml( jquery.inarray(htmlstring, arr))){ /*this line problem*/     }     else {         $(this).find('div.innerdiv').append(htmlstring);}   })  }); 

you can use jquery's length find if content present like

var checkcontent =  $(this).find('div.innerdiv').html().length; if(checkcontent> 0){ //contents present } 

note: have semi-colon missing in

$('.outerdiv').click(function () {  });// missing semi-colon. use 1 

Comments

Popular posts from this blog

apache - PHP Soap issue while content length is larger -

asynchronous - Python asyncio task got bad yield -

javascript - Complete OpenIDConnect auth when requesting via Ajax -