setting styles & attributes dynamically

S

sagar

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
 
D

David Dorward

sagar said:
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.
 
M

Michael Winter

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. said:
[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
 
T

Thomas 'PointedEars' Lahn

Michael said:
sagar said:
[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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,021
Latest member
AkilahJaim

Latest Threads

Top