jQuery Plugins » handlers https://jqueryplugins.info jQuery plugins, tutorials and resources Fri, 21 Oct 2011 18:13:19 +0000 en hourly 1 http://wordpress.org/?v=3.2.1 Do looping through items and adding handlers to it hurt performance https://jqueryplugins.info/2011/10/do-looping-through-items-and-adding-handlers-to-it-hurt-performance/ https://jqueryplugins.info/2011/10/do-looping-through-items-and-adding-handlers-to-it-hurt-performance/#comments Thu, 06 Oct 2011 16:15:35 +0000 Admin https://jqueryplugins.info/2011/10/do-looping-through-items-and-adding-handlers-to-it-hurt-performance/ Post link: Do looping through items and adding handlers to it hurt performance

Does it hurt in performance when I loop through list-items and add a clickhandler to all separate items? The reason I do this is because I would only like to...

]]>
Post link: Do looping through items and adding handlers to it hurt performance

Does it hurt in performance when I loop through list-items and add a clickhandler to all separate items?

The reason I do this is because I would only like to make the list item clickable if it contains an hyperlink.

The code I’m currenlty using is:

$  ('ul.paginator li').each(function() {
  if ($  ('a', this).length > 0) {
    $  (this).css('cursor', 'pointer');
    $  (this).click(function() {
      location.href = $  ('a', this).attr('href');
    });
  }
});

newest questions tagged jquery – Stack Overflow

]]>
https://jqueryplugins.info/2011/10/do-looping-through-items-and-adding-handlers-to-it-hurt-performance/feed/ 0
How do I attach event handlers using jQuery only to newly added elements? https://jqueryplugins.info/2011/09/how-do-i-attach-event-handlers-using-jquery-only-to-newly-added-elements/ https://jqueryplugins.info/2011/09/how-do-i-attach-event-handlers-using-jquery-only-to-newly-added-elements/#comments Tue, 06 Sep 2011 12:38:50 +0000 Admin https://jqueryplugins.info/2011/09/how-do-i-attach-event-handlers-using-jquery-only-to-newly-added-elements/ Post link: How do I attach event handlers using jQuery only to newly added elements?

There are objects where I have attached some events to. After some point, I create some more of those items and I want them also to be attached to the...

]]>
Post link: How do I attach event handlers using jQuery only to newly added elements?

There are objects where I have attached some events to.
After some point, I create some more of those items and I want them also to be attached to the same events.

If select elements using a jQuery selector and attach the handler to the event, the older object will have the same handler attached multiple times to their event.

What’s the proper way of doing this?

newest questions tagged jquery – Stack Overflow

]]>
https://jqueryplugins.info/2011/09/how-do-i-attach-event-handlers-using-jquery-only-to-newly-added-elements/feed/ 0
Neatening up custom event handlers – remove need for ‘event’ parameter https://jqueryplugins.info/2011/08/neatening-up-custom-event-handlers-remove-need-for-event-parameter/ https://jqueryplugins.info/2011/08/neatening-up-custom-event-handlers-remove-need-for-event-parameter/#comments Fri, 12 Aug 2011 15:09:19 +0000 Admin https://jqueryplugins.info/2011/08/neatening-up-custom-event-handlers-remove-need-for-event-parameter/ Post link: Neatening up custom event handlers – remove need for ‘event’ parameter

I’m building some objects that will trigger custom events, and I’m using jQuery’s bind and trigger to manage this for me, like so: function MyObject() { var _this = this;...

]]>
Post link: Neatening up custom event handlers – remove need for ‘event’ parameter

I’m building some objects that will trigger custom events, and I’m using jQuery’s bind and trigger to manage this for me, like so:

function MyObject() {

    var _this = this;

    this.onUpdate = function(fn) {
        $  (_this).bind('MyObject.update', fn);
    };

    this.update = function(params) {
        //Do stuff...
        $  (_this).trigger('MyObject.update', [updatedID]);
    };

}

My problem is when I come to register other callback functions with onUpdate – the functions I pass in need to include the ‘event’ parameter for trigger to work correctly, like so:

function myCallback(event, updatedID) {
    //Do more stuff...
}

var myobject = new MyObject();
myobject.onUpdate(myCallback);

Is there a nice way I can wrap the function that I pass in to bind in the onUpdate method, so that myCallback doesn’t need the ‘event’ parameter, as it seems a bit irrelevant for my purposes?

newest questions tagged jquery – Stack Overflow

]]>
https://jqueryplugins.info/2011/08/neatening-up-custom-event-handlers-remove-need-for-event-parameter/feed/ 0