473,779 Members | 1,873 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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=1 0; 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.borderCo lor (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 1583
sagar wrote:
I use the following ways to set attributes & styles e.g.

[divTag].style.height=1 0; 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.borderCo lor (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=1 0; 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.c om/faq/faq_notes/misc.html#mtCSS Un>
[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
2892
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 document.all, depending on browser support. This works just fine, with just one small problem: I want to set the style ONLY for screen media, not for printer media; the above statement appears to
12
2577
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 webshop. When user eventually ends up at the credit card processor's secure pages, the styles are quite different from the actual site's. I have managed to change some basics through a control
3
1932
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 = "/somepage.aspx?age=35&gender=M"
3
1162
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 do it but that seems to only be making one at a time changes, i want to be able to say this control is using the style ControlStyle1B from styles.css and if it's not validated property I want to use ControlStyle1F and so on.. how would i...
1
2379
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 properties, however, there seems to be one that I cannot set - ie, Name.. My code looks like this:
2
1560
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: ..WhatEver { ...
7
3509
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 attribute. This works for the content pages, but it doesn't seem able to apply the styles to the top master page even though I did set the master head tag to runat server. Is this by design? If so, what is the best way to apply styles to the top...
8
11255
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 HeaderText="Subject" Text="Subject" DataTextField="Subject" DataNavigateUrlFields="Id" DataNavigateUrlFormatString="~/Templates/View.aspx?id={0}" HeaderStyle-CssClass="columnStyle" ItemStyle-CssClass="columnStyle" />
3
3533
by: pbd22 | last post by:
Hi. How do I add the runat=server attribute on a buttonfield link dynamically? thanks!
0
9632
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10302
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10071
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9925
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8958
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6723
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5372
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5501
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3631
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.