GoogleSearchBox

Custom Search

Tuesday, August 20, 2013

How to pass multiple property (option) values as an argument to a method in JQuery

For an jQuery API we have multiples of options to use from for a method.
For example, for the jQuery UI Dialog widget we have a lot of options to choose from like we have maxHeight, minWidth, modal, resizable, draggable to achieve different functionalyties with the widget.

So how to use all or some of these options with the dialog method ?

Here is how we can do it:
We can create a variable containing all the options (name:value) with comma(,) in between multiple values (basically json notation) and then pass the variable to the dialog() method.

  $(function(){
 var dialogOpts = {
  show: true,
  hide: true,
  maxHeight: 400,
  minWidth: 850
 };
 $("#dialog").dialog(dialogOpts);
  });

where "dialog" is the div name inside your html's body as follows :
<div id="dialog" title="Basic dialog">

  <p>This is the default dialog which is useful for displaying information. The dialog window can be moved, resized and closed with the 'x' icon.</p>

  <p>This is the default dialog which is useful for displaying information. The dialog window can be moved, resized and closed with the 'x' icon.</p>

  <p>This is the default dialog which is useful for displaying information. The dialog window can be moved, resized and closed with the 'x' icon.</p>

  <p>This is the default dialog which is useful for displaying information. The dialog window can be moved, resized and closed with the 'x' icon.</p>

  <p>This is the default dialog which is useful for displaying information. The dialog window can be moved, resized and closed with the 'x' icon.</p>

  <p>This is the default dialog which is useful for displaying information. The dialog window can be moved, resized and closed with the 'x' icon.</p>

  <p>This is the default dialog which is useful for displaying information. The dialog window can be moved, resized and closed with the 'x' icon.</p>

</div>




Tags:
jquery option chain
jquery ui option chaining
jquery method option chaining
How to use multiple options to pass to a method in JQuery
How to use multiple options using options for jQuery method
How to use multiple options to pass to a method in JQuery

No comments:

Post a Comment