[jQuery] Re: Optimized Code

2008-12-17 Thread Dave Methvin
Ricardo's last point is important. Quite often you can improve jQuery code significantly by choosing convenient markup.

[jQuery] Re: Optimized Code

2008-12-17 Thread issya
Thank you for all of the great replies. I am going to implement some of this code now. As I mentioned before, It is always great to see how others would do something. Especially when I am newer to jQuery. On Dec 16, 8:40 am, Ricardo Tomasi wrote: > I'd write it like this: > > $(document).ready(f

[jQuery] Re: Optimized Code

2008-12-16 Thread Ricardo Tomasi
I'd write it like this: $(document).ready(function(){ function hideOthers(){ var sel = $('div.'+ $(what).val() || 'city' ); $('div').not(sel).hide(); sel.show(); }; hideOthers('input:checked'); $('input').click(function(){ hideOthers(this); $('select[id

[jQuery] Re: Optimized Code

2008-12-16 Thread Kean
It's interesting to know that $.map and $.grep can be used to a more generalized approach to this problem. Issya, you should look at Scott's code as it is extensible for future use. Definitely learned something new today. On Dec 15, 8:14 pm, Scott Sauyet wrote: > issya wrote: > > I recently made

[jQuery] Re: Optimized Code

2008-12-16 Thread Gordon
Don't run functions that return the same result multiple times, run them once and store the results in a variable. Example: $(document).ready () { var checkedVal = $('input:checked').val(); if (checkedVal = 'city') { // } } If you need to run more than 1 operation o

[jQuery] Re: Optimized Code

2008-12-15 Thread Scott Sauyet
issya wrote: I recently made this small script and was thinking it is a bit long. It works just fine, I was wondering if there is any way to make it shorter or is this right? Thanks in advance for the help. The previous suggestion, I think missed the point that you were only selecting the fir

[jQuery] Re: Optimized Code

2008-12-15 Thread issya
Thank you for the reply. It is always nice to see how experienced people would write it. At the same time I get to learn some new tricks. Thanks again On Dec 15, 7:28 pm, Kean wrote: > Here's how I will code it. > > jQuery(function($) > { // this means document.ready > >   var optionDisplay = f

[jQuery] Re: Optimized Code

2008-12-15 Thread Kean
Here's how I will code it. jQuery(function($) { // this means document.ready var optionDisplay = function() { var val = $("input:checked").val(); $(".city, .zip, .country").hide(); if (val.length > 0) $("."+val).show(); else $(".city").show(); $("#id_zip_code,