Connecting Tech Pros Worldwide Help | Site Map

resizing css div in javascript

 
LinkBack Thread Tools Search this Thread
  #1  
Old July 20th, 2005, 11:54 AM
Orson
Guest
 
Posts: n/a
Default 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



  #2  
Old July 20th, 2005, 11:54 AM
Fabian
Guest
 
Posts: n/a
Default Re: resizing css div in javascript

Orson hu kiteb:
[color=blue]
> 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.[/color]

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

  #3  
Old July 20th, 2005, 11:54 AM
Lasse Reichstein Nielsen
Guest
 
Posts: n/a
Default Re: resizing css div in javascript

"Orson" <bilge43@yahoo.com> writes:
[color=blue]
> 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:[/color]

Blindly trying isn't the best approach :)
[color=blue]
> 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);[/color]

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.
[color=blue]
> None of which have worked.[/color]
....[color=blue]
> Can someone point out the right way to do it?[/color]

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

/L
--
Lasse Reichstein Nielsen - lrn@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
  #4  
Old July 20th, 2005, 11:55 AM
Orson
Guest
 
Posts: n/a
Default Re: resizing css div in javascript


"Lasse Reichstein Nielsen" <lrn@hotpop.com> wrote in message
news:ad6wy6er.fsf@hotpop.com...[color=blue]
>
> 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.[/color]


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


 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,662 network members.