?
Solved

Style property is null even after setting at least one setting

Posted on 2004-11-02
4
Medium Priority
?
274 Views
Last Modified: 2012-06-22
I keep getting: "obj.style" is null or not an object error even after I have executed the following code:

if (document.getElementById){
        document.getElementById("obj")
        obj.style.fontSize='8pt'
        obj.style.fontFamily='Arial'
}

alert("obj.style: " + obj.style)
0
Comment
Question by:jkawah
  • 2
  • 2
4 Comments
 
LVL 13

Accepted Solution

by:
cLFlaVA earned 300 total points
ID: 12477195
Simple - where are you setting obj?

if (document.getElementById){
        var obj = document.getElementById("obj")
        obj.style.fontSize='8pt'
        obj.style.fontFamily='Arial'
}

alert("obj.style: " + obj.style)


I'm not sure what result you're going to get from alert("obj.style: " + obj.style), but i'm not sure it's what you expect...
0
 

Author Comment

by:jkawah
ID: 12477407
Thanks clflava, I had the "obj" defined globally, so I thought that would suffice? After the local definition (var obj = document.getElementById), I was able to display the actual settings to the style property; eg fontSize, etc. Displaying the "obj.style" just displays obj.style as [object] - which is still useful when I want to confirm that I have an object & it is not null or undefined.
0
 
LVL 13

Expert Comment

by:cLFlaVA
ID: 12477422
Ok.

Either way, you're not setting the obj to anything.  If it's declared globally, you'll still have to set it, like this:

if (document.getElementById){
        obj = document.getElementById("obj")
        obj.style.fontSize='8pt'
        obj.style.fontFamily='Arial'
}
0
 

Author Comment

by:jkawah
ID: 12477540
Yes, I forgot to type in my original question: menuobj = document.getElementById('obj'). But it is was like that in my code. Actually, here's exactly what was in the code (I modified it to make it generic):

menuobj=ie4? document.all.popmenu : ns6? document.getElementById("popmenu") : ns4? document.popmenu : ""


with the following variables defined globally, before the function that uses the above line (all this courtesy of Dynamic Drive):
var ie4=document.all
var ns6=document.getElementById&&!document.all
var ns4=document.layers
var menuobj
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Browsers only know CSS so your awesome SASS code needs to be translated into normal CSS. Here I'll try to explain what you should aim for in order to take full advantage of SASS.
SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
In this Micro Tutorial viewers will learn how to create navigation buttons that change on rollover, using CSS (Continuation of the CSS Image Sprite tutorial) Create a parent ID for all the list items       - Specify position: absolute and display: block…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
Suggested Courses
Course of the Month14 days, 5 hours left to enroll

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question