1

When the popup link is between the <script> tags it does not work.

if(data.userdata["money_back"] == 1){
 chat_list += '<a data-popup-open="popup-90">Download</a>';
}

I am pushing the When it is between the <body> tags it works fine

<body><a data-popup-open="popup-90">Download</a></body>

Does "data-popup-open" not work between <script> tags?

Here is a JSFiddle of basically what I'm trying to do:
http://www.jsfiddle.net/tkkpf9dp

vol7ron
  • 40,809
  • 21
  • 119
  • 172
Sam J.
  • 353
  • 1
  • 3
  • 12
  • You are using an `a` tag. That is a HTML element, it will only work as markup, not as a script. For it to work in your script, you need to `append` it to the `body` or to another element. – Hanlet Escaño Sep 28 '16 at 14:10
  • Sorry, if I wasn't clear. I'm not trying to run the `a` tag as a script. It is being displayed on the page for the user using javascript. The issue is, that when it is displayed nothing happens when you click it. – Sam J. Sep 28 '16 at 14:13
  • Gotcha. I can't exactly recreate the issue. Would you mind creating a simple fiddle? – Hanlet Escaño Sep 28 '16 at 14:20
  • https://jsfiddle.net/tkkpf9dp/ – Sam J. Sep 28 '16 at 14:46

2 Answers2

0

Something like that?

var popup = '<a data-popup-open="popup-90">Download</a>';
document.body.innerHTML += popup;
Shaq
  • 377
  • 5
  • 16
0

I think the problem is with the event handling. The event that should open open the pop up window may not be triggering. This is because you are creating a dynamic DOM element. The event handling of dynamic elements works in a different way. If you are using jQuery you can need to use something like this

Just add a class 'popup' to the 'a' tag like this

 <a class="popup" data-popup-open="popup-90">Download</a>

and in JavaScript

$('body').on('click','.popup',function() {

  var popup = $(this).data('popup-open');
  console.log(popup); //  For this example you will get the output 'popup-90' in the console
  // You can write the code to open the pop up here 
});
  • For more details about event handling of dynamic elements please check http://stackoverflow.com/questions/6658752/click-event-doesnt-work-on-dynamically-generated-elements – Samuel T Thomas Sep 28 '16 at 14:45
  • Thanks! I'm checking the link out. In the meantime here is a jsfiddle.net/tkkpf9dp of basically what I'm trying to do. If I add the class into the download link, it throws an error. – Sam J. Sep 28 '16 at 14:52
  • You are already using the 'popup' class for a div. and the display property of it is set as none. So please give another class for the 'a' tag. Make sure you change that in JS also – Samuel T Thomas Sep 28 '16 at 14:59
  • I corrected it and it still does not work. If I take the v`Download` link out of the javascript and put it in the HTML it works fine. – Sam J. Sep 28 '16 at 15:15