[jQuery] Re: Event Delegation and this question

2007-09-26 Thread Matt81

Hi. Thanks for the replies guys. I'll try what you've suggested when I
get into work today... will hopefully be what I'm looking for.

Again, many thanks.

On 25 Sep, 22:55, Michael Geary [EMAIL PROTECTED] wrote:
 I think event.target is what you're looking for all around, does that sound 
 right?

 //PAGINATION
 var $target = $(event.target);
 if ($target.is(a.pagination))
 {
 $target.parent().load($target.attr(href));
 return false;
 }

 -Mike

  From: Matt81

  I'm currently working on a site where I load in a series of
  links (in a list) with some pagination links underneath
  (a.pagination) into a div via an ajax request.

  In order to bind click events to the anchors with a class
  pagination, I've used the technique outlined on the jQuery
  website, whereby I attach a click to the body, and then test
  the event.target. Like so...

  $(body).click
  (
  function(event)
  {
  //PAGINATION
  if ($(event.target).is(a.pagination))
  {
  $(this).parent().load($(this).attr(href));
  return false;
  }
  }
  );

  This code does not work, and I believe the problem lies with
  the use of the this keyword - could it be I'm referring to
  the body element.
  As the content is loaded into the parent of the links, I need
  a solution based along these lines... so any help would be
  very much appreciated.



[jQuery] Re: Event Delegation and this question

2007-09-25 Thread Jörn Zaefferer


Matt81 schrieb:

Hi there.

I'm currently working on a site where I load in a series of links (in
a list) with some pagination links underneath (a.pagination) into a
div via an ajax request.
[...]

This code does not work, and I believe the problem lies with the use
of the this keyword - could it be I'm referring to the body element.
As the content is loaded into the parent of the links, I need a
solution based along these lines... so any help would be very much
appreciated.
  

Have you tried replacing this with event.target?

-- Jörn



[jQuery] Re: Event Delegation and this question

2007-09-25 Thread Michael Geary

I think event.target is what you're looking for all around, does that sound 
right?

//PAGINATION
var $target = $(event.target);
if ($target.is(a.pagination))
{
$target.parent().load($target.attr(href));
return false;
}

-Mike

 From: Matt81
 
 I'm currently working on a site where I load in a series of 
 links (in a list) with some pagination links underneath 
 (a.pagination) into a div via an ajax request.
 
 In order to bind click events to the anchors with a class 
 pagination, I've used the technique outlined on the jQuery 
 website, whereby I attach a click to the body, and then test 
 the event.target. Like so...
 
 $(body).click
 (
 function(event)
 {
 //PAGINATION
 if ($(event.target).is(a.pagination))
 {
 $(this).parent().load($(this).attr(href));
 return false;
 }
 }
 );
 
 This code does not work, and I believe the problem lies with 
 the use of the this keyword - could it be I'm referring to 
 the body element.
 As the content is loaded into the parent of the links, I need 
 a solution based along these lines... so any help would be 
 very much appreciated.