I've read through both the link you suggested and
http://www.tvidesign.co.uk/blog/improve-your-jquery-25-excellent-tips.aspx#tip12
but I can't understand how I would make event delegation work for me.

This is what I attempted:

function watchLinks()
  {
    $("a").click(function(e)
    {
      var linkClicked = $(e.target);
      if( linkClicked.is("a"))
      {
        var youWantToGoTo =
linkClicked.attr('href').substr(0,$(this).attr('href').length-4); //
Determine destination
        openPage(youWantToGoTo); // Open destination
        window.location.hash = youWantToGoTo; // Set the url #
        return false;
      }
    });
  };



malsup wrote:
> 
> 
>> I currently have a problem with the site I am designing, I'm using jQuery
>> to
>> load the content via AJAX, however. The script I'm using to watch for
>> when
>> the user clicks a link is:
>>
>> function watchLinks()
>>   {
>>     $("a").click(function()
>>     {
>>       var youWantToGoTo =
>> $(this).attr('href').substr(0,$(this).attr('href').length-4); //
>> Determine
>> destination
>>       openPage(youWantToGoTo); // Open destination
>>       window.location.hash = youWantToGoTo; // Set the url #
>>       return false;
>>     });
>>   };
>>
>> currently I call the function on the $(document).ready but this means
>> that I
>> cannot watch the links that are loaded dynamically.
>>
>> eg when the users loads the 'portfolio' page the watchLinks() function
>> isn't
>> active for the links which were loaded.
>>
>> I have tried setting watchLinks() as the callback but when the user
>> quickly
>> switches between pages the javascript seems to slow down to a snails pace
>> and pages don't load for a fairly long period of time.
>>
>> Is there a more efficient method?
> 
> 
> 
> Instead of binding event listeners to the anchors use event delegation
> instead:
> 
> http://www.learningjquery.com/2008/03/working-with-events-part-1
> 
> 
> 

-- 
View this message in context: 
http://www.nabble.com/.load%28%29-callback-tp21389522s27240p21392901.html
Sent from the jQuery General Discussion mailing list archive at Nabble.com.

Reply via email to