1

I have a jQuery Plugin that I use myself which modifies the selected value of select items on a page.

In my own code the plugin automatically executes as soon as it is included in the page this code in the plugin file.

jQuery('Document').ready(function(){
jQuery('select').SelectOptions();
});

this automatically executes my plugin on all select items on the page.

Obviously for people other than myself who might come across this on github I'd like to change this slightly. I still think the idea of auto execute is good but my question is.

  1. Don't setup autoexecute at all, let the developer call the code.
  2. Call autoexecute on All Select items and let the developer modify the code if he doesnt want that.
  3. Autoexecute, but modify my selector called in the plugin js file to modify only select tags with a particular class - such as below

.

jQuery('Document').ready(function(){
jQuery('select .selectoptions').SelectOptions();
});

Is there any established protocol for this?

5

The plugin usually specifies a default behavior and also accepts a selector, e.g:

jQuery().selectOptions() // default selector 'select'
jQuery( '.selectOptions' ).selectOptions() // Custom selector, gives the user more control.

I would not recommend automatically executing under any circumstances.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.