473,322 Members | 1,504 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,322 software developers and data experts.

setting styles & attributes dynamically

Hello everyone,

I am developing a AJAX based IM application. I use javascript to
dynamically generated small windows using nested <div> within the
web-page.

I use the following ways to set attributes & styles e.g.

[divTag].style.height=10; for styles
[divTag].setAttribute("id","outer") for attributes

I have two problems with this
1)I have to set a large number of attributes & styles, is there any
shorter/compact technique.
2) [divTag].style.borderColor (I need this for shadow effect)&
[divTag].scrollTop (I need this to keep d scroll bar at bottom) cant be
set, setting them makes no difference

Please provide help to solve above problems, or tell me if I am using
the wrong approach.
Thank You
Sagar

Dec 23 '05 #1
3 1567
sagar wrote:
I use the following ways to set attributes & styles e.g.

[divTag].style.height=10; for styles
The height property takes a length, not an integer. Units are required (and
failing to include them will cause your script to break in some browsers,
if you were in Standards mode (via Doctype Switching) then it would break
in more browsers).
[divTag].setAttribute("id","outer") for attributes
I thought IE didn't support setAttribute? (I could be wrong).
1)I have to set a large number of attributes & styles, is there any
shorter/compact technique.
Set as few attributes as possible, CSS handles almost everything these days.
Then set a className rather then each property one by one.
2) [divTag].style.borderColor (I need this for shadow effect)&
[divTag].scrollTop (I need this to keep d scroll bar at bottom) cant be
set, setting them makes no difference


I've no idea why setting borderColor wouldn't work. Try providing a URL so
we can see the problem in context. I've never played with scrollTop, so I
can't make any suggestions there.

--
David Dorward <http://blog.dorward.me.uk/> <http://dorward.me.uk/>
Home is where the ~/.bashrc is
Dec 23 '05 #2
On 23/12/2005 10:42, David Dorward wrote:
sagar wrote:


[snip]
[divTag].style.height=10; for styles


The height property takes a length, not an integer. Units are
required (and failing to include them will cause your script to break
in some browsers, if you were in Standards mode (via Doctype
Switching) then it would break in more browsers).


Though one may happen upon rare occasions where the value is only ever a
number. <http://www.jibbering.com/faq/faq_notes/misc.html#mtCSSUn>
[divTag].setAttribute("id","outer") for attributes


I thought IE didn't support setAttribute? (I could be wrong).


It does, but satisfactorily, badly or incorrectly, depending upon what
it's being used to do. :-/

If a script deals with IE then it is scripting a HTML document. In that
case, stick to using the property shortcuts.

[snip]

Mike

--
Michael Winter
Prefix subject with [News] before replying by e-mail.
Dec 23 '05 #3
Michael Winter wrote:
On 23/12/2005 10:42, David Dorward wrote:
sagar wrote:
[divTag].setAttribute("id","outer") for attributes

I thought IE didn't support setAttribute? (I could be wrong).


It does, but satisfactorily, badly or incorrectly, depending upon what
it's being used to do. :-/

If a script deals with IE then it is scripting a HTML document. In that
case, stick to using the property shortcuts.


While it is all too true that IE does not support XHTML at all, the
"property shortcuts" are defined for XHTML 1.0 documents, too, as
W3C DOM Level 2 HTML applies for both HTML 4.01 and XHTML 1.0 documents.

<URL:http://www.w3.org/TR/DOM-Level-2-HTML/>, "Abstract".
<URL:http://www.w3.org/TR/DOM-Level-2-HTML/html.html#ID-5353782642>
PointedEars
Dec 23 '05 #4

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

Similar topics

1
by: C A Upsdell | last post by:
I have a site where I am setting a style dynamically, using the JS statement: obj.style.backgroundImage = 'url(img/bak_page.jpg)'; where 'obj' is either document.getElementById(id), or...
12
by: dan.vendel | last post by:
Hi, I know nothing about javascript, but quite a lot about regulat html and CSS. Have bumped into a problem that people in this fine congregation perhaps can help me with. I'm making a...
3
by: Boban Dragojlovic | last post by:
in the codebehind portion of a page, I dynamically create a series of hyperlinks that I add to the page. in that code, I have something like this: dim h as new hyperlink h.NavigateURL =...
3
by: Brian Henry | last post by:
I have my styles.css file filed with the styles used for the site, now how would i specify a control to have a certain style id from that styles.css file in code? i thought mycontrol.style would...
1
by: Rob Meade | last post by:
Hi all, I have a loop in my code which builds the controls on the page. I at one stage need to add some hidden input controls dynamically, I have achieved this, and I have set their...
2
by: Guenther Schabus | last post by:
e.Item.CssClass = "SelectedTab";Hello all, I am using .NET 1.1, VS 2003 - Syntax is C# I am trying to change ('enhanced') attributes set by an css-file dynamically. Content of an CSS-File:...
7
by: sasquatch | last post by:
Hi, I've a a site with nested master pages and content pages. I tried using a theme with a stylesheet in the app_themes directory referencing it in the web.config file from a pages tag theme...
8
by: Jeff | last post by:
ASP.NET 2.0 I'm wondering how to set the color of a visited HyperLinkField (the link text) in a GridView?? Here is the markup of the HyperLinkField I have problems with: <asp:HyperLinkField...
3
by: pbd22 | last post by:
Hi. How do I add the runat=server attribute on a buttonfield link dynamically? thanks!
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.