473,412 Members | 3,763 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,412 software developers and data experts.

New User -- "Null or not an object"

I'm a few weeks new to JS, and am having a problem. I have a simple INTERNAL style in a web page and I know that style is working. The problem arises when I try to run a script that changes one of that style's properties.

The style is...
--------------------------------------------------
..xtable, .xtable TD, .xtable TH
{
background-color:black;
color:white;
font-family:arial;
}
-------------------------------------------------

(the above style is workinh OK), but the following script gets the error "document.classes.xtable" is null or not an object.

---------------------------------------------------
function testerx()
{
document.classes.xtable.all.color='Yellow'
}
--------------------------------------------------

Both of these are in the <HEAD> section, and I've tested it with the style both before and after the script.

Thsnks.

---Robert---
Jul 23 '05 #1
2 1982
Please do not post to Usenet in (Multipart) HTML format. Use a newsreader
program if your Web interface is unable to create plain text messages (use
alt.test or your favorite *test* group for tests). See news.newusers.infos.

Mr X wrote:
The style is...
*--------------------------------------------------*
*.xtable, .xtable TD, .xtable TH
{
background-color:black;
color:white;
font-family:arial;
}*
*-------------------------------------------------*

(the above style is workinh OK), but the following script gets the error
"document.classes.xtable" is null or not an object.

*---------------------------------------------------*
*function testerx()
{
document.classes.xtable.all.color='Yellow'
}*
*--------------------------------------------------*


You are using fantasy syntax and IE's error message is misleading
one more time (see <http://jibbering.com/faq/>). There is no such
property like document.classes, so this reference evaluates to
`undefined' and the `undefined' literal value has indeed no `xtable'
property as it has no properties at all.

Instead, CSS selectors defined in a stylesheet are part of the
document.styleSheets[...].cssRules collection in the W3C DOM, where "..."
refers to the zero-based index of the stylesheet. The IE DOM implements
this as document.styleSheets[...].rules. Provided that the stylesheet you
posted is the first one that applies to the document and the selector you
posted is the first one in that stylesheet, you can access its "color"
property's value with

document.styleSheets[0].cssRules[0].style.color = "yellow";

for UAs standards compliant in this regard like Mozilla

document.styleSheets[0].rules[0].style.color = "yellow";

for IE. Be sure to check for DOM support prior to access:

function testerx() // identifier should be more descriptive!
{
var s, r;
if (typeof document != "undefined"
&& typeof document.styleSheets != "undefined"
&& (s = document.styleSheets)
&& typeof s.length != "undefined"
&& s.length > 0)
{
if (typeof s[0].cssRules != "undefined") // standards compliant
{
r = s[0].cssRules;
}
else (typeof s[0].rules != "undefined") // IE
{
r = s[0].rules;
}
if (r
&& typeof r.length != "undefined"
&& r.length > 0
&& typeof r[0].style != "undefined"
&& (s = r[0].style)
&& typeof s.color != "undefined")
{
s.color = "yellow";
}
}
}

See

<http://pointedears.de.vu/scripts/test/whatami>

for details.
HTH

PointedEars
Jul 23 '05 #2
Please do not post to Usenet in (Multipart) HTML format, see
news.newusers.infos and <http://insideoe.tomsterdam.com/>.

Mr X wrote:
The style is...
*--------------------------------------------------*
*.xtable, .xtable TD, .xtable TH
{
background-color:black;
color:white;
font-family:arial;
}*
*-------------------------------------------------*

(the above style is workinh OK), but the following script gets the error
"document.classes.xtable" is null or not an object.

*---------------------------------------------------*
*function testerx()
{
document.classes.xtable.all.color='Yellow'
}*
*--------------------------------------------------*


You are using fantasy syntax and IE's error message is misleading
one more time (see <http://jibbering.com/faq/>). There is no such
property like document.classes, so this reference evaluates to
`undefined' and the `undefined' literal value has indeed no `xtable'
property as it has no properties at all.

Instead, CSS selectors defined in a stylesheet are part of the
document.styleSheets[...].cssRules collection in the W3C DOM, where "..."
refers to the zero-based index of the stylesheet. The IE DOM implements
this as document.styleSheets[...].rules. Provided that the stylesheet you
posted is the first one that applies to the document and the selector you
posted is the first one in that stylesheet, you can access its "color"
property's value with

document.styleSheets[0].cssRules[0].style.color = "yellow";

for UAs standards compliant in this regard like Mozilla

document.styleSheets[0].rules[0].style.color = "yellow";

for IE. Be sure to check for DOM support prior to access:

function testerx() // identifier should be more descriptive!
{
var s, r;
if (typeof document != "undefined"
&& typeof document.styleSheets != "undefined"
&& (s = document.styleSheets)
&& typeof s.length != "undefined"
&& s.length > 0)
{
if (typeof s[0].cssRules != "undefined") // standards compliant
{
r = s[0].cssRules;
}
else (typeof s[0].rules != "undefined") // IE
{
r = s[0].rules;
}
if (r
&& typeof r.length != "undefined"
&& r.length > 0
&& typeof r[0].style != "undefined"
&& (s = r[0].style)
&& typeof s.color != "undefined")
{
s.color = "yellow";
}
}
}

See

<http://pointedears.de.vu/scripts/test/whatami>

for details.
HTH

PointedEars
Jul 23 '05 #3

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

Similar topics

7
by: Pablo J Royo | last post by:
Hello: i have a function that reads a file as an argument and returns a reference to an object that contains some information obtained from the file: FData &ReadFile(string FilePath); But ,...
13
by: Don Vaillancourt | last post by:
What's going on with Javascript. At the beginning there was the "undefined" value which represented an object which really didn't exist then came the null keyword. But yesterday I stumbled...
1
by: putty | last post by:
I found a few posts of people asking about insertCell()/insertRow() not working in IE6 SP2, and a few others about getting "null is null or not an object" errors, but no one posted a solution...
13
by: gary | last post by:
Hi, We all know the below codes are dangerous: { int *p = new int; delete p; delete p; } And we also know the compilers do not delete p if p==NULL. So why compilers do not "p = NULL"...
14
by: MuZZy | last post by:
Hi, Lately i've been (and still am) fixing some memory leaks problems in the project i just took over when i got this new job. Among the other issues i've noticed that for localy created objects...
4
by: Peter Hemmingsen | last post by:
Hi, I have a dotnet object (implemented in mc++ and used in c#) which have a property called "Info". The Info property is also a dotnet object (implemented in mc++). In the constructor of the...
5
by: rengeek33 | last post by:
I am building a SQL statement for Oracle and need one part of it to read: , myvar = null, myvar2 = "1", myvar3 = "0", myvar4 = null, etc. I am constructing this string using the String...
8
by: chaos | last post by:
Hi all i have error in my forget password where user key in their email address .But the page occur an error "document.email_address is null or not object . <script language="javascript">...
6
by: cleary1981 | last post by:
I have adapted code from http://dunnbypaul.net/js_mouse/ I want to use a button to create new draggable divs but i keep getting error "is null or not an object" heres the code <html> <head>...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...
0
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
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...

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.