473,545 Members | 2,714 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.class es.xtable" is null or not an object.

---------------------------------------------------
function testerx()
{
document.classe s.xtable.all.co lor='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 1996
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.i nfos.

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.class es.xtable" is null or not an object.

*---------------------------------------------------*
*function testerx()
{
document.classe s.xtable.all.co lor='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.classe s, 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.styleS heets[...].cssRules collection in the W3C DOM, where "..."
refers to the zero-based index of the stylesheet. The IE DOM implements
this as document.styleS heets[...].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.styleS heets[0].cssRules[0].style.color = "yellow";

for UAs standards compliant in this regard like Mozilla

document.styleS heets[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.styleS heets != "undefined"
&& (s = document.styleS heets)
&& 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.i nfos and <http://insideoe.tomste rdam.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.class es.xtable" is null or not an object.

*---------------------------------------------------*
*function testerx()
{
document.classe s.xtable.all.co lor='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.classe s, 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.styleS heets[...].cssRules collection in the W3C DOM, where "..."
refers to the zero-based index of the stylesheet. The IE DOM implements
this as document.styleS heets[...].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.styleS heets[0].cssRules[0].style.color = "yellow";

for UAs standards compliant in this regard like Mozilla

document.styleS heets[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.styleS heets != "undefined"
&& (s = document.styleS heets)
&& 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
20337
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 , for example, when the file doesnt exists, i should not return any reference to a bad constructed object, so i need something as a NULL reference...
13
3067
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 across "null" string. I know that I will get an "undefined" when I try to retrieve something from the DOM which doesn't exist. I have used null...
1
3160
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 anywhere or noted this tiny yet curious change in SP2.. so here it is: In IE6 SP2 rows must be inserted into a tBody instead of a Table directly,...
13
3086
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" automatically after programs do "delete p"?
14
3129
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 it makes difference to explicitly put them to null after working with them is done - it somehow makes the GC collect them sooner, like here: void...
4
2745
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 "main" object I want to initialize the property "Info" to null in a way that will make the c# programmer (the user) able to write: if...
5
1909
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 object with the following code: theSQL.Append(" , myvar = " & FormatValue(MyClass.DB_CHAR1, Me.MyVar))
8
1643
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"> document.email_address.reset(); </script> This is use to clear the text in the text box <input type="text" title="Please enter your email address"...
6
4944
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> <title>Drag and drop module</title> <style type="text/css"> #canvas {
0
7502
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...
0
7434
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7692
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. ...
0
7946
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7791
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...
1
5360
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3491
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...
0
3470
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1045
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.