Hello everyone, I'm a newbie to javascript, and would absolutely love if someone could help me understand why it's returning that document.getElementById("footer") is null. What I need this to do is to add the appropriate class to the element with id="footer".
This is a php document in order to render only specific javascript depending on a variable from a cookie. If you view the link to the full script below, Everything but the problem area is working.
Code:
PHP Code:
#Check to see if cookie has been set
if(isset($_COOKIE['isExtended']))
{
#If it has, set $isExtended var to Cookie var
$isExtended = $_COOKIE['isExtended'];
#and echo current value
echo "isExtended = $isExtended ;";
#and set element's rendered class
[COLOR="Red"]if($isExtended == 0)
{
echo "document.getElementById('footer').setProperty('class','min');";
}
else {
echo "document.getElementById('footer').setProperty('class','max');";
}[/COLOR]
}
#If it hasn't, echo default value
else
{
echo "isExtended = 1 ;";
}
Same problem will occur with getProperty.
I didn't check if you were using this method with attribute style, but that will not work either.
05-13-2009, 01:25 PM
blindmikey
Thanks for the replies guys, I really appreciate it.
However, I've tried using that line of code aswell.
I've used:
$('footer').setClass('min');
document.getElementById('footer').className='min';"
and the line of code posted above.
Each time I get a return message that 'footer' is null... which I don't understand since there is a div with the id of 'footer'...
I'm quite lost...
05-13-2009, 04:50 PM
Kor
Code:
$('footer').setClass('min');
That is not a javascript plain code. $() means nothing in javascript. Nor setClass() method (this should be a custom function placed somewhere else... impossible to know how it works). Do you use a framework? In this case call the framework creators to help you. Usually frameworks bring troubles.
05-13-2009, 05:44 PM
blindmikey
Hey Kor,
Thank you for your reply!
Yes, that particular way of fetching an element by id is from the Mootools framework, however, it's not the framework that I'm having an issue with, as no matter what syntax I use, even the most basic document.getElementById('footer').className='min';" returns that the footer is null.
The only question I have is why would it return the message of "document.getElementById("footer") is null" ?
I would greatly appreciate anyone that could help me understand this.
05-14-2009, 01:47 AM
Kor
we need to see the whole picture. Do you have a test page?
05-14-2009, 08:22 AM
javawebdog
element null issue
May very well be a sequence problem.
Your javascript is attempting to take an action on an element BEFORE it is rendered to the page, hence the element is null.