Having issue in javascript code. light box does not open second time -


i have code opens lightbox when user click link. opens lightbox, when user clicks on overlay closes or hides overlay , lightbox. when user click on link again open lightbox again not open. here code

var el = document.getelementbyid('element');             var body = document.getelementsbytagname('body');             el.innerhtml = '<p><a id="clickme" href="#">click me</a></p>';             document.getelementbyid('clickme').onclick = function (e) {                 e.preventdefault();                 if (overlay) {                 overlay.style.display = 'block';             } else {                 document.body.innerhtml = '<div id="overlay" style="display:block;position:absolute;width:100%;height:100%;opacity:0.3;z-index:100;background:#000;"></div>'+document.body.innerhtml;                                }                 document.body.innerhtml = '<iframe id="frame" style="position:absolute;display:block;z-index:101;width:50%;height:50%;margin:10% 20%;border:10px solid #ccc;border-radius:10px;" src="http://www.example.com/"></iframe>'+document.body.innerhtml;                  document.getelementbyid('overlay').onclick = function() {                 document.getelementbyid('overlay').style.display = 'none';                     document.getelementbyid('frame').style.display = 'none';             }     } 

how can open lightbox again when user clicks link second time?

you set style display:none on close clicking link doesn't change display property. effect: box stays invisible.

simple solution: add display:block or whatever need there opening function.

in addition: opening function create new element each time executed. add test prevent that:

var overlay = document.getelementbyid('overlay'); if(overlay){     overlay.style.display = 'block'; } else {     //create box } 

Comments

Popular posts from this blog

Delphi XE2 Indy10 udp client-server interchange using SendBuffer-ReceiveBuffer -

Qt ActiveX WMI QAxBase::dynamicCallHelper: ItemIndex(int): No such property in -

Enable autocomplete or intellisense in Atom editor for PHP -