Lightbox failing

No errors but it should be giving me a lightbox functionality but it only directs me to the image path when I click.
http://www.codefundamentals.com/test.php

Tips on how the code looks is appreciated. This was in jQuery but I tried converting it as best I could.

Alright, I managed to get it working. How can I do this node insertion more easily? The comment is what I need.

    //box=document.createTextNode("<div id=\"lightbox\"><p>Click to close</p><div id=\"content\"><img src="+anchor_href+" alt=\"Clients\"></div><p>Click to close</p></div>");
    box=document.createElement("div");
    box.setAttribute("id","lightbox");
    document.getElementsByTagName("body").item(0).appendChild(box);

I’m not sure you can use HTML in createTextNode().
AFAIK that would add them as text, not nodes.

Did you try innerHTML =

1 Like

createTextNode is just something I had before. I didn’t actually try it. Sorry for being confusing.

Derp, why did I not think of that…thank you.

Hmm, my closing feature only seems to work once? Can someone offer explanation? I can open, then close, then open again, and then it fails. I assume my if/else condition in “trigDisplay()” is faulty.

http://www.codefundamentals.com/test.php

Got it. Added a condition to test for null.

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.