Skip to content

Open modal by clicking on dynamically generated link #60

@kolobix

Description

@kolobix

Hi,

I´m getting several elements dynamically by an Ajax-Request. Each of these elements contains a link which should open a modal when clicked. How to achieve this since dynamically generated elements are not 'recongnized' by the jquery selector?

At the moment I use this to initialize the modal:
$(".modal_trigger_login").leanModal({top : 200, overlay : 0.8, closeButton: ".modal_close" });

This works for all the elements which are not generated dynamically but not for the elements which are generated dynamically.

So I tried it with something like this:

$(document).on('click', '.modal_trigger_login', function(){
    $(this).leanModal({top : 200, overlay : 0.8, closeButton: ".modal_close" });
});

But this only works when I click the links a second time and it also seems like it 'initializes' the leanModal on each click, because on every click it adds another lean_overlay div to the page.

Thx in advance and sorry for my english

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions