JanWillem
JanWillem

Reputation: 352

Dynamically set jQuery object option/property

To be sure I'm not messing up terms, here is the code example. I'm using jQuery Nivoslider and I want to be able to change the used effect(s) when I change them in a listbox. I am able to show in a div what the effect should be, but the actualy effect is not applied to the slider.

I was expecting something like: jQuery("#slider").effect = values; but that doesn't seem to work.

Here is part of the code:

// Listbox    
 <select id="slider-effect" name="effect[]" size="10" multiple="multiple" style="height:100px;">
<option value="sliceDownRight">Slice Down to Right</option>
<option value="sliceDownLeft">Slice Down to Left</option>
<option value="boxRain">Rain Boxes</option>
<option value="boxRainReverse">Reverse Box Rain</option>
</select>

 // Javascript that setups NivoSlider (actual div is missing, just an example)
 // shortend options for the example
 jQuery(window).load(function() {
jQuery('#slider').nivoSlider({"effect":"boxRandom"});}); 


 // Javascript that should change the option effect
 // this shows me the effect I set (not included in the code here)

jQuery('#slider-effect').change(function() {
var values = jQuery("#slider-effect").val();
jQuery('#slider-message').html('<p>Effect set to:' + values + '</p>'); 
jQuery("#slider")["effect"] = values;
                                                  });


        });

Upvotes: 0

Views: 1218

Answers (1)

Pointy
Pointy

Reputation: 413717

I don't see any provisions in that particular plugin for accepting updated options after it has been initialized. Most of the jQueryUI plugins support something like this:

jQuery('#something').pluginName('options', updatedOptions);

where "updatedOptions" is an map of new values. However, I don't see any trace of support for something like that in the source code to that plugin. It accepts all sorts of options when it starts up, but there's no way to tell it about changing anything.

It might be possible to convince it to completely re-initialize, but with plugins like that it can be complicated because they (might) do all sorts of weird stuff to the DOM.

Upvotes: 1

Related Questions