Forums

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

Home Forums JavaScript [Solved] jQuery Click event only works once

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

    I’ve got an anchor link setup:

    Code:

    and some jQuery to fade in a background and fade it back out when you click:

    Code:
    $(function() {

    var box = $(“

    “).addClass(“darkCover”).click(function() {
    $(this).fadeOut();
    });

    $(‘.background’).click(function() {
    $(“body”).prepend(box);
    box.fadeTo(“s”,0.9);
    });

    });

    For some reason the click events only fire once. The first time everything works fine, but after you fade the background in and out once it just doesn’t respond. If you click again, I can see in the inspector that the div is getting created, but with a display of none and clicking on it doesn’t activate the click even to get rid of it.

    I know it has something to do with only loading once when the DOM loads, but I don’t know what to do about it. I’ve been at it for hours and any help would be appreciated, thanks.

Viewing 1 post (of 1 total)
  • The forum ‘JavaScript’ is closed to new topics and replies.