Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting width as a percentage using jQuery

Tags:

jquery

width

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

like image 442
Prasad Avatar asked Jan 23 '10 19:01

Prasad


People also ask

How do I change the width of a percentage in HTML?

Try It: Set the width of an image using a percentage and resize your browser window. For the width attribute, you can also use percentages, where 100% is the total space available. So, if you wanted an image to be one quarter the width of the window, you could set width to 25% (one quarter of 100% is 25%).

What is width percentage CSS?

The <percentage> CSS data type represents a percentage value. It is often used to define a size as relative to an element's parent object. Numerous properties can use percentages, such as width , height , margin , padding , and font-size .

How does jQuery width work?

jQuery width() and height() MethodsThe width() method sets or returns the width of an element (excludes padding, border and margin). The height() method sets or returns the height of an element (excludes padding, border and margin).


1 Answers

Using the width function:

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

will turn:

<div id="somediv" /> 

into:

<div id="somediv" style="width: 70%;"/> 
like image 107
Darin Dimitrov Avatar answered Sep 21 '22 00:09

Darin Dimitrov