Snitz Forums 2000
Snitz Forums 2000
Home | Profile | Register | Active Topics | Members | Search | FAQ
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 Community Forums
 Community Discussions (All other subjects)
 How to set style of element in javascript?
 New Topic  Topic Locked
 Printer Friendly
Author Previous Topic Topic Next Topic  

GoodMorningSky
Junior Member

122 Posts

Posted - 06 April 2005 :  21:12:24  Show Profile
Hi all
I can set each attribute of style using style[] collection like following..

var targetCtrl = document.all["textInput1"];
targetCtrl.style["background"]="white";

But, I don't know how to set entire style.

targetCtrl.style="background:Red;LEFT:330px;POSITION:absolute;TOP:24px;display:none;"

this doesn't work!
How can I set style attribute by one shot?

Software Engineer.
MCSD.NET, SCWCD

Davio
Development Team Member

Jamaica
12217 Posts

Posted - 06 April 2005 :  21:37:54  Show Profile
You can't. You have to do it individually.

Support Snitz Forums
Go to Top of Page

Davio
Development Team Member

Jamaica
12217 Posts

Posted - 06 April 2005 :  22:01:26  Show Profile
I take that back. You can change many of the style attributes at one time. By changing the class of the element.

So you have a 2 css styles for a textbox. Whenever you want to change the styles, just change the class name instead.

document.getElementById(objId).className = className;

objId would be the ID of the element you want to change the style of.
className is the name of the class you want to change the element to.

Support Snitz Forums
Go to Top of Page

D3mon
Senior Member

United Kingdom
1685 Posts

Posted - 07 April 2005 :  04:48:02  Show Profile  Visit D3mon's Homepage
You can also use:

document.getElementById(objId).style

This page may help you out:
http://www.comptechdoc.org/independent/web/cgi/javamanual/javastyle.html


Snitz 'Speedball' : Site Integration Mod : Friendly Registration Mod
"In war, the victorious strategist only seeks battle after the victory has been won"

Edited by - D3mon on 07 April 2005 04:49:31
Go to Top of Page

Davio
Development Team Member

Jamaica
12217 Posts

Posted - 07 April 2005 :  10:11:48  Show Profile
That's what he is already using D3mon. But using the style attribute, you still need to set the styles one by one. Unless you use the method I suggested. Create 2 css styles then switch the class name on the atrribute to the second style.

Support Snitz Forums
Go to Top of Page

D3mon
Senior Member

United Kingdom
1685 Posts

Posted - 07 April 2005 :  12:14:42  Show Profile  Visit D3mon's Homepage
ah yes, sorry. I hadn't read the full thread.


Snitz 'Speedball' : Site Integration Mod : Friendly Registration Mod
"In war, the victorious strategist only seeks battle after the victory has been won"
Go to Top of Page

GoodMorningSky
Junior Member

122 Posts

Posted - 07 April 2005 :  12:36:26  Show Profile
Thank you all!
For the whole project it's good to go with class.
I wonder why they don't give string style property.
Maybe they want to force us to use class..^^;

Software Engineer.
MCSD.NET, SCWCD
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Topic Locked
 Printer Friendly
Jump To:
Snitz Forums 2000 © 2000-2021 Snitz™ Communications Go To Top Of Page
This page was generated in 0.38 seconds. Powered By: Snitz Forums 2000 Version 3.4.07