0 0 Votes

jQuery: Set the width of an element in percent

Question by Guest | 14/12/2018 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

Stefan Trost

Show Profile | Message
Avatar
1Best Answer
1 Vote

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 %.
15/12/2018 at 19:56

ReplyPositive Negative

NetLabel

Show Profile | Message
Avatar
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.
15/12/2018 at 21:47

ReplyPositive Negative
Reply

Related Topics

jQuery: Replace element
Question | 1 Answer

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 articles on askingbox.com. How to do.