0

Okay so I'm building a custom Wordpress theme and I need a custom modal window (div) to appear when a user clicks a certain link on my page. I designed the modal window, and linked certain parts of it (such as 'X' button to close) with jQuery functions.

Works fine when I put the div onto the page itself, but when I try to create that same DIV with a separate jQuery function which gets called when a user clicks the link, it creates and displays that div, but the function for the 'login-close' class link does absolutely nothing this time.

Here's how I create the DIV with jQuery:

var passion = jQuery(this).attr('data-passion');

var div = $('<div id="itinerary-modal"> <a class="login-close" href="#"><i class="fa fa-times"></i></a> <p>You have successfully added<br> <span>'+passion+'</span><br> to your wishlist. </p> <a href="" class="btn">See my wishlist</a> <a href="#" class="btn">OK</a> </div>');

$("#content").append(div);

div.show(); /* "itinerary-modal" is display:hidden in CSS */

This is of course all embedded in a link.click jQuery function. As I said, displays the div just fine but I want it to function (close on 'login-close' class link) as it did when it was placed on the page as pure HTML.

Zannix
  • 1,473
  • 3
  • 16
  • 26

1 Answers1

0

Yep the answer is on the link Barmar posted. Use .on().

Community
  • 1
  • 1
theleebriggs
  • 571
  • 2
  • 5