Link to home
Start Free TrialLog in
Avatar of jkawah
jkawah

asked on

Style property is null even after setting at least one setting

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)
ASKER CERTIFIED SOLUTION
Avatar of cLFlaVA
cLFlaVA

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jkawah
jkawah

ASKER

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.
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'
}
Avatar of jkawah

ASKER

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