00 Votes

jQuery: Set the width of an element in percent

Question by Guest | 2018-12-14 at 23:19

I would like to change the width of some elements with jQuery. The information should be provided in percent, so I would like to set the element with the id "div1" to 50% width, for example. Is that possible?

ReplyPositiveNegativeDateVotes
0Best Answer2 Votes

You can use the function width() for that.

With the code

$('#div1').width('50%');

you are setting the width of

<div id="div1">

to 50 %.
2018-12-15 at 19:56

ReplyPositive Negative
00 Votes

You can also directly address the CSS of your element. That would look like this:

$('#div1').css({'width': '50%'});

The result would of course be the same.
2018-12-15 at 21:47

ReplyPositive Negative
Reply

Related Topics

jQuery: Show and hide elements

Tutorial | 0 Comments

Important Note

Please note: The contributions published on askingbox.com are contributions of users and should not substitute professional advice. They are not verified by independents and do not necessarily reflect the opinion of askingbox.com. Learn more.

Participate

Ask your own question or write your own article on askingbox.com. That’s how it’s done.