News:

Tekforums.net - The improved home of Tekforums! :D

Main Menu

using javascript to modify a css property

Started by bytejunkie, February 11, 2008, 09:55:13 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

shofty

can anyone tell me if the following should work and if not why not?

Basically, I use lightbox quite a lot. however it really bugs me how if a user clicks a thumb before the page is completely loaded the lightbox script doesnt get called.

my solution is to put all the thumbs into the gallery div. then hide the div as standard and only make it visible once the page has loaded. using the body onload event. so my body onload event now calls the prepareLinks function below (alert proves its getting called) and the initLightbox function in another js page.

ive moved the alert to prove the script below is looping through the divs, but it never seems to see the gallery div. is this because its hidden in css? I would still have expected the code to loop through it even if its hidden.


function prepareLinks() {
  alert(function triggered);
    var links = document.getElementsByTagName("div");
        for (var i=0; i        if (links[i].getAttribute("class") == "gallery") {
            links[i].setAttribute = ("visibility", "visible")
                }
            if (links[i].getAttribute("class") == "loading") {
            links[i].setAttribute = ("visibility", "hidden")
return false;
                }
            }
        }


I wondered if the problem wasnt:

1. because the div is hidden. it cant read a div it cant see. but i suspect this isnt the case

2. because Im modifying a css property appertaining to the div, not the div itself.

Matt

shofty

think Ive found it but I cant test at work...

as i loop through the divs, im looking for a class called gallery. however gallery is a ID.... so simple.