I’m making a plugin (my first one, sorry if messy 😉 ) for jquery, everything works fine, except for events. Events always apply to the last element, no matter what. if only one element everything works great, but with two or more elements events crash.
I’ve been looking through similar cuestions, but I can’t find the solution to mine.
the code is on:
http://jsbin.com/itajow/edit#javascript,html
and the demo is in
just filter or go through pagination to see the problem.
Thanks in advance!!
The
selfvariable used in the methods was used in different ways – somewhere it was made a local variable (var self = thiswithin the method) and other places it was used as a variable with a lifetime outside of the method (by omittingvar). I don’t know if this was intentional to gain some other effect, but making the variable local fixed the problem of paging only happening to the last element.The updated code is at http://jsbin.com/itajow/11/edit
Note: the declaration
addNav:function(self)takes in theselfobject, but it’s called both with and without a parameter in the code, so the first line of the function fixes this by doingself = self || this.Edit
To make the list filtering work, the event binding may be rewritten as follows:
and the
addFilteradomethod should takeinputas a parmeter rather than find it itself.(the code, to keep it here on SO)