Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript Help With Variables

  • This topic is empty.
Viewing 1 post (of 1 total)
  • Author
    Posts
  • #37392
    cizmic
    Participant

    Hello there. I have a while loop that adds an onclick event listener for multiple images.
    I know what the prob is. The while loop increments the variable a by 1, which in turn edits the onclick attribute for the HTML tag.
    Is there any way around this?

    Below is the code:


    function nanoboxInit () {
    imgTags = document.getElementsByTagName("img");
    while (a < imgTags.length) {
    if (imgTags[a].className == "nanobox-img") {
    imgTags[a].onclick = function () { nanoboxOpen(this); }
    }
    a++;
    }
    fatTony(0);
    }
Viewing 1 post (of 1 total)
  • The forum ‘JavaScript’ is closed to new topics and replies.