Hi HK
It doesn't works because elements loaded via AJAX isn't available when the page is just loaded. Before version 1.3.1 to bind events to elements loaded via AJAX you must use the LIVEQUERY plugin. Version (1.3) 1.3.1 added the live() and die() methods that should solve your problem.

Have a look at: http://docs.jquery.com/Events/live#typefn

MaurĂ­cio

-----Mensagem Original----- De: "HK" <hkosm...@gmail.com>
Para: "jQuery (English)" <jquery-en@googlegroups.com>
Enviada em: segunda-feira, 2 de fevereiro de 2009 09:21
Assunto: [jQuery] DOM manipoulation after ajax load



Hello,

I have the following case and I don't know what's happening...

I have a sidebar #menu where in document ready I have:

$('#menu).load('/menu')

#menu is loaded with something like:
<div id="menu">
 <div id="level1">
    various <a> tags
 </div>

 <div id="level2">
   various <a> tags
 </div>

 <div id="level3">
 various <a> tags
 </div>

</div>

Now I want to assign to each of the <a> tags some click functions. I
do :

$(document).ready(function() {
  $('#menu).load('/menu');
  $('#level1 a').each(function(){$(this).click(function(){alert
'test'})})
})

But this doesn't work. Can jquery access elements it has loaded with
load ajax function?

thanks

Reply via email to