Setting width as a percentage using jQuery

Prasad picture Prasad · Jan 23, 2010 · Viewed 112.5k times · Source

How can I set the width of a div as a percentage using jQuery?

Answer

Darin Dimitrov picture Darin Dimitrov · Jan 23, 2010

Using the width function:

$('div#somediv').width('70%');

will turn:

<div id="somediv" />

into:

<div id="somediv" style="width: 70%;"/>