I am attempting to change a plugin’s options, on the fly. But I cannot find how that’s accomplished. Though, I’m positive I’ve seen it done before.
here’s a simple plugin with 1 option:
<a href="javascript:void(0)" onclick="change_the_option(40)">click me</a>
$(document).ready(function() {
$(#menu).animateMenu({
padding:20
})
});
function change_the_option(valchange){
//somehow modify the option here, I'm guessing
}
That is loaded with the page, automatically. However, I may wish to change the padding option dynamically, without reloading the entire page.
Basically, if someone clicks a link or any selector I choose, I want to change padding:20 to padding:40, or whatever.
Does anyone have experience with modifying plugin options, on the fly?
If you haven’t already, have a look at
http://docs.jquery.com/Plugins/Authoring
from “Defaults and Option” on down to the end. Ideally you would want to be able to call your plugin passing some parameters to do what you want. For instance:
or
Up to you exactly how you want it to work, but it should return the jquery object so that it ca be properly chained. This is all explained in the above link.
But in this way, you could have nice clean code, that you could chain along with other jquery, like so: