Hey all,
I have just started using JQuery and have come across a hurdle.  I am
creating DIVs on the fly (using a JQuery).  For these DIVs, I have
them tagged to a Class.  For this Class, I have an Event tied to it.
For some reason, the Event doesn't seem to work for the newly created
DIVs.  However, it works for the hard-coded DIVs.

Here's an example of what I mean.

I'm using a Javascript to create the DIVs on the fly.
e.g.

function createDiv() {
    var divHtml = $("#existingDivs").html();
    $("#existingDivs").html( divHtml +
        "<div class=classTiedToEvent>ClassTiedtoEvent class test</
div>" );
}

I then have an Event tied to the class, "classTiedToEvent," like so...
e.g.

$(document).ready(function(){
    $("div").click(function(){
      if ( $(this).hasClass("classTiedToEvent") )
        $(this).animate({ left: -10 }, 75)
               .animate({ left: 10 }, 75)
               .animate({ left: -10 }, 75)
               .animate({ left: 10 }, 75)
               .animate({ left: 0 }, 75);
    });
});

or...

e.g.

$(document).ready(function(){
    $(".classTiedToEvent").click(
        function() {
            alert("clicked");
        }
    );
});

I've tried variations of the 2 above functions and neither have
worked.  However, they do work if I were to hardcode the
"classTiedToDiv" DIV in my HTML.

The DIVs that I generate with my first Javascript function
("createDiv") do have the correct Class associated with them (I
think), because they take on the attributes I've defined in my
stylesheet.

Any ideas what I'm doing wrong?

Please let me know if you'd like me to clarify.  Thanks.

Dave

Reply via email to