[jQuery] Re: Iterating over 1000 items - optimizing jquery

2007-08-21 Thread Michael Geary
> > From: Michael Geary > > Then, instead of binding event handlers to all of the individual > > buttons, just bind a single event handler to the parent form: > > > >$('#order_form').click( function( event ) { > > var $target = $(event.target); > > if( $target.is('img.increment')

[jQuery] Re: Iterating over 1000 items - optimizing jquery

2007-08-21 Thread Michael Geary
> From: Dan Eastwell > The thinking behind it is not to add the button images using > javascript, so that if you don't have javascript, you don't > have useless and confusing buttons. You can still generate the code on the server. Just use this code in : img.increment, img.decrement

[jQuery] Re: Iterating over 1000 items - optimizing jquery

2007-08-21 Thread Dan Eastwell
That is genius Mike, I'm extremely grateful. It worked perfectly - even with adding my images using jquery, the total time was ~1.2 secs, which I see as acceptable for 1000 s. Many thanks once more, Dan. PS - if it's not too much trouble, could you explain /why/ it works? Especially the event.

[jQuery] Re: Iterating over 1000 items - optimizing jquery

2007-08-21 Thread Dan Eastwell
Thanks for the reply, Mike, The thinking behind it is not to add the button images using javascript, so that if you don't have javascript, you don't have useless and confusing buttons. I'll try your form event handle, so thanks for that, Dan. On 8/21/07, Michael Geary <[EMAIL PROTECTED]> wrote

[jQuery] Re: Iterating over 1000 items - optimizing jquery

2007-08-21 Thread Michael Geary
> From: Dan Eastwell > I'm doing an order form for a bookstore. The order form has > over 500 items in it, so jquery runs slowly... Can't you do any of this on the server? All of the code generation - the IMG tags and the zebra striping - would cost next to nothing while the page is being genera

[jQuery] Re: Iterating over 1000 items - optimizing jquery

2007-08-21 Thread Dan Eastwell
I've got this: $('[EMAIL PROTECTED],[EMAIL PROTECTED]') .after("") .next("[EMAIL PROTECTED]'-']").bind('click', false, doPlusMinus) .next("[EMAIL PROTECTED]'+']").bind('click', true, doPlusMinus); Which works, but the two 'nexts' are adding maybe a second each, if I can get rid of th

[jQuery] Re: Iterating over 1000 items - optimizing jquery

2007-08-21 Thread Jonathan Sharp
Sending code via e-mail stinks! The basic logic for the after is: // Append our images $(...).after( // Create a new image element $('') // Bind your click event to it .bind('click', false, doPlusMinus) // Add the sceond image element after it .after( // You may be

[jQuery] Re: Iterating over 1000 items - optimizing jquery

2007-08-21 Thread Dan Eastwell
I think the problem with Jonathon's solution is that the added html can't have a click event bound to it? I'm not sure. I've tried stripping that code down, so that the bind click is just alerting, but that won't work. Any thoughts? .after( $('') .bind('click', false, doPlusM

[jQuery] Re: Iterating over 1000 items - optimizing jquery

2007-08-21 Thread Erik Beeson
hmm, seems like your original version should have that problem too. Maybe the increment and decrement operators take care of the conversion. At any rate, should be: $qty_field.val(parseInt($qty_field.val())-1); And: $qty_field.val(parseInt($qty_field.val())+1); --Erik On 8/21/07, Dan Eastwell

[jQuery] Re: Iterating over 1000 items - optimizing jquery

2007-08-21 Thread Dan Eastwell
Oh, one more thing, $qty_field.val($qty_field.val()-1); Is concatenating as a string, not adding! Just a small point, and nothing compared to the errors I'd make in coding without any testing!! Cheers, Dan. On 8/21/07, Dan Eastwell <[EMAIL PROTECTED]> wrote: > No, not at all, many thanks to

[jQuery] Re: Iterating over 1000 items - optimizing jquery

2007-08-21 Thread Dan Eastwell
No, not at all, many thanks to both - I still don't think it's beaten, but I'll have another look with what you and Jonathon's examples have given me (by example) in my understanding of chaining jquery. Jonathon's is very elegant, but needs some debugging to get it to work - I think I need to wor

[jQuery] Re: Iterating over 1000 items - optimizing jquery

2007-08-21 Thread Erik Beeson
Yes, it looks like he intends to close the first 'after' before starting the second. --Erik On 8/21/07, Dan Eastwell <[EMAIL PROTECTED]> wrote: > > > Fantastic, thanks Jonathon! > > One problem - only the minus appears - does the first after call need > to be closed before the second? > > Thanks

[jQuery] Re: Iterating over 1000 items - optimizing jquery

2007-08-21 Thread Erik Beeson
heh, I took so long writing my reply, a bunch of other people replied in the mean time. Anyways, I suggest you use firebug (console.time/console.timeEnd) to see how long each version takes. --Erik On 8/21/07, Erik Beeson <[EMAIL PROTECTED]> wrote: > > You do a lot of repetitive selecting. Someth

[jQuery] Re: Iterating over 1000 items - optimizing jquery

2007-08-21 Thread Erik Beeson
You do a lot of repetitive selecting. Something like this might help (untested): $('td [EMAIL PROTECTED]').filter('[EMAIL PROTECTED],[EMAIL PROTECTED]') .after('') .next().bind("click", function() { var $qty_field = $(this).siblings('[EMAIL PROTECTED]'); if ($qty_field.val() > 0 )

[jQuery] Re: Iterating over 1000 items - optimizing jquery

2007-08-21 Thread Dan Eastwell
Fantastic, thanks Jonathon! One problem - only the minus appears - does the first after call need to be closed before the second? Thanks, Dan. On 8/21/07, Jonathan Sharp <[EMAIL PROTECTED]> wrote: > This can be reduced to this: > > $(document).ready(function() { > function doPlusMinus(even

[jQuery] Re: Iterating over 1000 items - optimizing jquery

2007-08-21 Thread Jonathan Sharp
This can be reduced to this: $(document).ready(function() { function doPlusMinus(event) { qty_field = $(this).parent('td').find('[EMAIL PROTECTED]'); var num = $(qty_field).val(); $(qty_field).val( num + (event.data === true ? 1 : (num > 0 ? -1 : 0)) ); } // Fi

[jQuery] Re: Iterating over 1000 items - optimizing jquery

2007-08-21 Thread Dan Eastwell
Thanks Corey, I've now got my code down to what follows. If I swap qty_field for input_text in the function bound to the image button's click event, obviously, any click increments all input values. Is there any way cutting this code down further? Thanks, Dan. $(document).ready(function() {

[jQuery] Re: Iterating over 1000 items - optimizing jquery

2007-08-21 Thread seedy
You shouldn't need to use the .each $('td [EMAIL PROTECTED]@type=text]').after('stuff') will append to all elements that match the selector, no need to go into a loop with each. Dan Eastwell wrote: > > > Hi, > > I'm doing an order form for a bookstore. The order form has over 500 > items in

[jQuery] Re: Iterating over 1000 items - optimizing jquery

2007-08-21 Thread Dan Eastwell
Hi, I've improved my own function - to this: $(document).ready(function() { addPlusMinus("[EMAIL PROTECTED]@type=text]"); addPlusMinus("[EMAIL PROTECTED]@type=text]"); $("table.summarytable tr:even").addClass("odd"); }); function addPlusMinus(input_text){