473,386 Members | 1,973 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

resizing css div in javascript

I have a CSS div defined as follows :
<div id="col-2" >

In some circumstances I want to change its width.
I have tried all the following within a javascript function:

document.getElementById("col-2").width= "900";
document.getElementById("col-2").resizeTo(900, 520);
document.getElementById("col-2").width.value= "900";
document.all.col-2.resizeTo(900, 520);
document.layers["col-2"].resizeTo(900, 520);

None of which have worked.

Within the stylesheet I initially had col-2 defined as an ID. Clutching at
straws I changed it to a class but that made no difference.

Can someone point out the right way to do it?
Thanks
Orson
Jul 20 '05 #1
3 24391
Orson hu kiteb:
I have a CSS div defined as follows :
<div id="col-2" >

In some circumstances I want to change its width.
I have tried all the following within a javascript function:

document.getElementById("col-2").width= "900";
document.getElementById("col-2").resizeTo(900, 520);
document.getElementById("col-2").width.value= "900";
document.all.col-2.resizeTo(900, 520);
document.layers["col-2"].resizeTo(900, 520);

None of which have worked.


Thats because its a style. So you need something like...

document.getElementById("col-2").style.width= "900";

(warning: I havent double checked this)
--
--
Fabian
Visit my website often and for long periods!
http://www.lajzar.co.uk

Jul 20 '05 #2
"Orson" <bi*****@yahoo.com> writes:
I have a CSS div defined as follows :
<div id="col-2" >

In some circumstances I want to change its width.
I have tried all the following within a javascript function:
Blindly trying isn't the best approach :)
document.getElementById("col-2").width= "900";
document.getElementById("col-2").resizeTo(900, 520);
document.getElementById("col-2").width.value= "900";
document.all.col-2.resizeTo(900, 520);
document.layers["col-2"].resizeTo(900, 520);
You should test whether
document.getElementById("col-2")
works at all. Try starting out with:
alert( document.getElementById("col-2") );
If that works, go on to changing the position.
None of which have worked. .... Can someone point out the right way to do it?


Try:
document.getElementById("col-2").style.width = "900px";
That would use CSS to set the width.

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #3

"Lasse Reichstein Nielsen" <lr*@hotpop.com> wrote in message
news:ad**********@hotpop.com...

You should test whether
document.getElementById("col-2")
works at all. Try starting out with:
alert( document.getElementById("col-2") );
If that works, go on to changing the position.
Try:
document.getElementById("col-2").style.width = "900px";
That would use CSS to set the width.

Many thanks for the suggestions. I have finally got it all working.
Your suggestion to check my progress using alerts was instrumental in my
sorting it all out.

O
Jul 20 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: riki | last post by:
Hi, i have a big problem...i'm using one jscript for resizing of all of my pics in popUp...in main html i'm having many little pics and clicking on them they open in popUp and resize to larger...
13
by: Jon Yeager | last post by:
I need to display a bunch of pictures that are all of various dimensions into a fixed dimension space, like MSN Messenger does with its user photos in the chat windows. Forcing image dimensions...
1
by: Paul Fi | last post by:
can some one help me here coz this is really killing me! the problem is, i have this javascript code in my aspx page that i want it to work on almost all browsers, especially opera and safari : ...
14
by: Seige | last post by:
Ever had headache when you can't resize the background width using CSS: body{ background: url(/images/bg.jpg) ; background-width: 800px; } It won't work, would it? Of course not, it's not even...
3
by: PCgeek | last post by:
sorry moved this over to javascript forum, didn't mean to post 2x! Hi guys, I'm trying to put the finishing touches on my website and could really use some help on this particular issue. My page...
13
by: bgraphics2031 | last post by:
I'm trying to get this iframe to dynamically resize by dragging a vertical bar, but it's not working in Mozilla (It originally worked in IE but I've been trying to port it over). Any help will be...
9
by: dli07 | last post by:
Hello, I'm trying to convert a piece of code that creates a dynamic vertical resizing bar in a table from internet explorer to firefox. It's based on a post from...
1
by: Nick | last post by:
Hi, I have created a html page from Java and I have added a .js file which can resize a TextArea inside the html on mousedown event. <script src="C:\temp\resize.js"</script> <table<tr><td...
8
by: brahmaforces | last post by:
Hi Folks, I am using cherrypy and python. I am trying to get a user profile image to resize on the client side before uploading to the server. PHP has a gd library that does it it seems. Has...
2
by: wannasee | last post by:
Hello everybody, I am new at javascript and I would like to write a script that resizes the input fieds of an html table depending on the entered text. The input fields are placed in table cells...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.