By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,238 Members | 1,196 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,238 IT Pros & Developers. It's quick & easy.

i need to make a variable that can set the width of a div

P: 1
i need to make a variable that can set the width of a div

var width=object.style.width
width=100

should change the objects width
is there a function that can do this??
May 10 '08 #1
Share this Question
Share on Google+
1 Reply


hsriat
Expert 100+
P: 1,654
You can't do it this way.

Once you write var width = object.style.width, you are storing the width of the object in a variable. Then you write width=100. This won't set the width of the element as you expect, but will change the value of the variable only.

The only short-form thing you can have is
Expand|Select|Wrap|Line Numbers
  1. var obj = document.getElementById('div_Id'); //create object referance
  2. obj.style.width = '100px'; //assign width
May 11 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.