Update jQuery UI Widget Options

By  on  

We're all used to passing options when instantiating an object, whether it be JavaScript or any other language.  Whether or not you can update those options later is usually up to the framework, and somehow many wont let you update them once they've been passed in.  Depending on how the initialization of the object is done, sometimes that makes sense, but in most cases you should be able to update an option at any given time.

I recently needed to update a jQuery UI widget option and here's how you update any given option:

this.$editor.inlineEditor('option', 'forceOpen', true);

jQuery UI is mostly a legacy technology these days so I'm mostly passing this tip on for those having to maintain old code.  This does teach a good lesson:  always provide a method for modifying initial options, even if you don't foresee a reason to do so!

Recent Features

  • By
    An Interview with Eric Meyer

    Your early CSS books were instrumental in pushing my love for front end technologies. What was it about CSS that you fell in love with and drove you to write about it? At first blush, it was the simplicity of it as compared to the table-and-spacer...

  • By
    fetch API

    One of the worst kept secrets about AJAX on the web is that the underlying API for it, XMLHttpRequest, wasn't really made for what we've been using it for.  We've done well to create elegant APIs around XHR but we know we can do better.  Our effort to...

Incredible Demos

Discussion

    Wrap your code in <pre class="{language}"></pre> tags, link to a GitHub gist, JSFiddle fiddle, or CodePen pen to embed!