Srinath Murugula
Srinath Murugula

Reputation: 582

My js popup is not working dynamically

My javascript function is

$(document).ready(function() {
    $('#popup').jPop({
        type: "img",
        gallery: true,
        onClick: '',
        onClose: ''
    });     
});

<a id="popup" href="data:image/jpeg;base64,${mapo.encodedString}"> 
    <img src...> <img> 
</a>

Here popup is working well for first tag.

I am removing the old tags $("#popup").remove();.

Then after when i am dynamically adding a href tags

$("#old").append(" < a id='popup' href.. >< img tag > < / a >");

Here after appending the image is not associated with jquery popup for next time.here pop up is not working for this dynamical added image.There is no mistake in adding dynamical tag.

Is there any solution for this?

Upvotes: 1

Views: 135

Answers (1)

BenG
BenG

Reputation: 15154

you will need to call $('#popup').jPop again after you append the new popup.

maybe split out the jpop creation into a new function

function createPopup(){
    $('#popup').jPop({
      type: "img",
      gallery: true,
      onClick: '',
      onClose: ''
    });   
}

then you can call in in document ready and after when you append the new image.

$(document).ready(function(){
   createPopup();     
});

$("#old").append(" < a id='popup' href.. >< img tag > < / a >");
createPopup();

Upvotes: 1

Related Questions