Good abstraction Ricardo. But I wouldn't use trigger like that. It feels a bit overkill plus that it might hurt performance on the client.
My approach would be something like this, doing exactly the same + better performance: $.fn.showIf = function( show, arg ) { return this[ show ? 'show' : 'hide' ]( arg ); }; $(document).ready(function(){ $('#edit-profile-country').each(function(){ var value = $(this).val(); $('#state').showIf( value == 'US' ); $('#province').showIf( value == 'CA' ); }) }); / Johan On 4 Apr, 22:46, Ricardo <ricardob...@gmail.com> wrote: > Nice. I'd just take advantage of event triggering to make it a bit > simpler: > > $.fn.showIf = function( show, arg ) { > return this[ show ? 'show' : 'hide' ]( arg ); > > }; > > $().ready(function(){ > > $('#edit-profile-country').change(function(){ > var value = $(this).val(); > $('#state').showIf( value == 'US' ); > $('#province').showIf( value == 'CA' ); > }).trigger('change'); > > }); > > cheers, > - ricardo >