aligreene
aligreene

Reputation: 37

Specify width or height as percentages (%) in jquery options?

Quick question: When specifying options for a plugin, is it possible to use percentages (%) for specifying width or height?

Like in this example:

var options = $.extend( {
   width: 300,
   height: 200
  }

It doesn't seem to allow for % to be added for specifying width.

Upvotes: 0

Views: 3270

Answers (3)

tvanfosson
tvanfosson

Reputation: 532605

If you use percentages or any units, you have to put the values in quotes. If you don't it's not legal javascript syntax. You're also missing a closing parenthesis and semicolon.

var options = $.extend( {
   width: '300%',
   height: '200%'
});

Upvotes: 0

Gabriele Petrioli
Gabriele Petrioli

Reputation: 196217

Use strings for the value..

var options = $.extend( {
   width: '300%',
   height: '200%'
  }

Upvotes: 1

Sascha Galley
Sascha Galley

Reputation: 16091

.width( value ): value An integer representing the number of pixels, or an integer along with an optional unit of measure appended (as a string).

Source: jQuery .width( value ), so in your case:

var options = $.extend( {
   width: '300%',
   height: '200%'
}

Upvotes: 0

Related Questions