[jQuery] Re: Reducing this code.

2007-04-17 Thread Sean Catchpole
Also, what's Sean talking about when he says: "lets say the focus function gets called twice (through malicious javascript or a quirky browser) then the toggle state of the class will be off. But in general I prefer your implementation. " Is this something i need to worry about? Is this specif

[jQuery] Re: Reducing this code.

2007-04-17 Thread Karl Swedberg
On Apr 17, 2007, at 2:25 AM, Klaus Hartl wrote: $(function(){ var toggle = function() { $(this).parent().toggleClass('on') }; $('fieldset").find('input, select, textarea').focus(toggle).blur (toggle); }); I'd choose this approach in order to avoid typing the class name "on" in more

[jQuery] Re: Reducing this code.

2007-04-17 Thread fambizzari
Thanks - funnily enough i downloaded firebug earlier on today. Also, what's Sean talking about when he says: "lets say the focus function gets called twice (through malicious javascript or a quirky browser) then the toggle state of the class will be off. But in general I prefer your implementati

[jQuery] Re: Reducing this code.

2007-04-17 Thread Sean Catchpole
> I'd choose this approach in order to avoid typing the class name "on" in > more than one place (which may lead to errors if you want to change that > one and forget it somewhere - not here maybe but in larger chunks of code). It actually avoids duplicating the whole code to access the parent,

[jQuery] Re: Reducing this code.

2007-04-16 Thread Klaus Hartl
Klaus Hartl schrieb: I'd choose this approach in order to avoid typing the class name "on" in more than one place (which may lead to errors if you want to change that one and forget it somewhere - not here maybe but in larger chunks of code). It actually avoids duplicating the whole code to a

[jQuery] Re: Reducing this code.

2007-04-16 Thread Klaus Hartl
Sean Catchpole schrieb: Hello, Perhaps this would be a faster way of typing this (yet still easy to read): $(function(){ $("fieldset").find("intput,select,textarea") .focus(function(){ $(this).parent().addClass("on"); }) .blur(function(){ $(this).parent().removeClass("on"); }); });

[jQuery] Re: Reducing this code.

2007-04-16 Thread Karl Rudd
In Firefox you can use the "Profile" feature of Firebug ( http://www.getfirebug.com ). For most other browsers you'd have to stick with something like this: var start = new Date().getTime(); // stuff to time var milliseconds = (new Date().getTime()) - start; Karl Rudd On 4/17/07, [EMAIL PR

[jQuery] Re: Reducing this code.

2007-04-16 Thread [EMAIL PROTECTED]
Thanks guys. As it would be negligible, there's no need to worry. But how would you test speed in js? (My background is php) Aaron Heimlich wrote: Off hand I'd have to say Sean's is faster, since it's only searching for "every fieldset in the document" once instead of three times like your

[jQuery] Re: Reducing this code.

2007-04-16 Thread Karl Rudd
Good point Aaron. I agree, I think Sean's would be better, and clearer. Karl Rudd On 4/17/07, Aaron Heimlich <[EMAIL PROTECTED]> wrote: Off hand I'd have to say Sean's is faster, since it's only searching for "every fieldset in the document" once instead of three times like yours (unless jQuer

[jQuery] Re: Reducing this code.

2007-04-16 Thread Aaron Heimlich
Off hand I'd have to say Sean's is faster, since it's only searching for "every fieldset in the document" once instead of three times like yours (unless jQuery does some result caching that I'm not aware of, in which case the difference is probably negligible). But, as Karl said, you'd really have

[jQuery] Re: Reducing this code.

2007-04-16 Thread Karl Rudd
You'd have to test it. Could be either. Karl Rudd On 4/17/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: Thanks guys. Very helpful. So, which would be faster... $("fieldset input, fieldset select, fieldset textarea") or $("fieldset").find("intput,select,textarea") Thanks x 1,000

[jQuery] Re: Reducing this code.

2007-04-16 Thread [EMAIL PROTECTED]
Thanks guys. Very helpful. So, which would be faster... $("fieldset input, fieldset select, fieldset textarea") or $("fieldset").find("intput,select,textarea") Thanks x 1,000,000 Karl Rudd wrote: You're on the right track. Yes you can join (or "chain") the "focus" and "blur" functions to

[jQuery] Re: Reducing this code.

2007-04-16 Thread Karl Rudd
You're on the right track. Yes you can join (or "chain") the "focus" and "blur" functions together. You also don't need to "return false" in the "focus" and "blur" functions, as that would/should "cancel" the event. You can also replace $(document).ready( function() {... with $( function() {..

[jQuery] Re: Reducing this code.

2007-04-16 Thread Sean Catchpole
Hello, Perhaps this would be a faster way of typing this (yet still easy to read): $(function(){ $("fieldset").find("intput,select,textarea") .focus(function(){ $(this).parent().addClass("on"); }) .blur(function(){ $(this).parent().removeClass("on"); }); }); Also note that http://www.j