mercredi 13 mai 2015

Check if variable have already been appended

Got a problem. In the following fiddle I have tried to exemplify how I wish to check for if the variable "htmlstring" has already been appended, and if so, then not to append another. On the other hand if it haven't been appended, ofcourse append it.

http://ift.tt/1A1I0La

How do I make this work? All in all, what I need is a if-else code, that will check for previous appended variable. If none has been appended it will append, if the container already contains the appended variable "htmlstring" then it ofcourse shouldn't append a 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 is the problem*/
    }
    else {
        $(this).find('div.innerdiv').append(htmlstring);}

 })
 });

Aucun commentaire:

Enregistrer un commentaire