vendredi 17 novembre 2017

Javascript: Avoiding multiple pop up boxes / check if div is empty

So I am using a button to generate a pop up message and javascript to fill it. My issue is that I got it to appear before but every time the button was clicked it just created another window on top of the old one. So I created an if statement to check whether it was empty or not... that is my current roadblock. Any suggestions for a noob idiot? Appreciation for all responses in advance.

var box = document.getElementById('popupbox');

if($(box).text().length) {
  box.style.display = "block";
  var content = document.createElement('div');
  content.className = 'boxstyle';
  content.innerHTML = ' ...a handful of tags...';
  box.appendChild(content);}
else{
  box.style.display = "block"; }

Aucun commentaire:

Enregistrer un commentaire