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)
jkawahAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

cLFlaVACommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
jkawahAuthor Commented:
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
cLFlaVACommented:
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
jkawahAuthor Commented:
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
CSS

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.