Dave's Brain

Browse - Programming Tips - How can I dynamically load a jquery.ui plugin?

Date: 2016nov28
Library: jQueryUI
Language: javaScript

Q.  How can I dynamically load a jquery.ui plugin?

A. Here's how

function dynamicallyLoadPlugin(plugin, id) { var func = $.fn[plugin]; func.call($('#' + id)); }
jQueryUI plugins live in $.fn.thePlugin so the first line of the function get a reference to it. Next we need to call that function. Normally its done like this: $('#id').plugin(). So we use standard javaScript call() which lets us specify the "this" variable.

Add a comment

Sign in to add a comment
Copyright © 2008-2017, dave - Code samples on Dave's Brain is licensed under the Creative Commons Attribution 2.5 License. However other material, including English text has all rights reserved.