Hi Krafton,

In addition to Dan's excellent reply, I'd like to suggest a couple good resources:

Brandon Aaron has written a plugin to help with binding events to elements after they're inserted into the DOM:
        http://dev.jquery.com/browser/trunk/plugins/behavior

Also, this tutorial discusses a few ways to handle such binding:
        http://docs.jquery.com/Tutorials:AJAX_and_Events

Hope that helps.

--Karl
_________________
Karl Swedberg
www.englishrules.com
www.learningjquery.com



On Jun 25, 2007, at 10:08 AM, Dan G. Switzer, II wrote:


Krafton,

I'm using this code in jquery to load  the content of a div
(primaryContentContainer) by cliking on <a href...

$(document).ready(function()
    {
        $("a").click(function()
             {
                   var link=$(this).attr("id");
                   $("#primaryContentContainer").load("pages/"+link
+".html");
             };
} );

I'm using this kind of link :  <a href="#" id="dos622">Dos v6.22 boot
disk</a>

It's working fine, but if i put a link in a page that's loaded
by .load(), the link seems not working.

Exemple: clicking on <a href="#" id="dos622">Dos v6.22 boot disk</a>
load the page dos622.html in the div with
id="primaryContentContainer". But the same (or other) link if
contained in dos622.html will not work.

I don't have much experience with jquery, can someone help me please?

If I understand you correctly, you're saying that if the "dos622.html" file
contains links, it's not picking up the click handler, correct?

If so, this is the expected behavior. When you run a jQuery function it only
runs for elements currently in the DOM. If you create new DOM
elements--manually or by loading a DOM fragment via AJAX--you would need call the code to re-initialize click handler for the new content. You can do
this via a callback.

However, you're probably going to run into another issue. The "id" attribute must be unique. This means you can't have more than one element in the DOM with an "id" of "dos622". The way that you're currently using the code, you may not run into a problem, but if you'd do a $("#dos622"), you'd only get
back a single node.

-Dan


Reply via email to