Saturday, December 26, 2009

Re: [jQuery] Rebinding not working

Use the callback of load function

$('#transactions').hide().load(url, function(){
    $('#transactions ul li a').bind('click tap', exp_iphone_get_trans);
}).fadeIn();


On Sat, Dec 26, 2009 at 19:29, mrtoner <don@donmorris.com> wrote:
Okay, the answer is probably obvious to you that are old hands at
jQuery, but I'm not seeing it. I finally figured out that if I load
new content via AJAX:

     $(document).ready(function(e){
       ...
       exp_iphone_get_sales();
     });

     function exp_iphone_get_sales() {
       ...
       $('#transactions').hide().load(url).fadeIn();
     }

I also need to rebind the click/tap (I'm using jQTouch) events to the
new content:

     function exp_iphone_get_sales() {
       ...
       $('#transactions').hide().load(url).fadeIn();
       $('#transactions ul li a').bind('click tap',
exp_iphone_get_trans);
     }

Unfortunately, clicking on one of the transactions:

     <div id="transactions">
       <ul class="rounded">
         <li class="arrow"><a href="#transaction"
id="7U735587N3003591E" class="slide">...</a></li>
          ...
       </ul>
     </div>

doesn't execute exp_iphone_get_trans(). And, oddly, when the page
loads, exp_iphone_get_trans() *is* executed -- no click or tap needed.

Using jQ 1.3.2; I also tried

       $('#transactions ul li a').live('click tap',
exp_iphone_get_trans());

to no avail. Any suggestions?

No comments: