Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Is null or undefined 1

Status
Not open for further replies.

TheCandyman

Technical User
Sep 9, 2002
761
0
0
US
I'm having trouble with this simple JS. It looks at the anchor tag in the URL, breaks it into an array (which works) and changes the background color based on that value which is where i get an error. I can see the correct value saved in 'anchorValue' (a2697), but get an error saying it's unable to get the value of the property 'style': is null or undefined. What did i miss?


Code:
<script type="text/javascript">
		var anchorValue;
		var url = document.location;
		var strippedUrl = url.toString().split("#");
		if(strippedUrl.length > 1)
		anchorValue = strippedUrl[1];
                alert(anchorValue);
		document.getElementById(anchorValue).style.backgroundColor='white';
</script>

...
...
...


<li><a name="a2697"></a>......
 
Your anchor doesn't have an ID, yet you are using getElementBy[red]Id[/red]. Since the anchor has no id, it can't find it and returns a null or undefined.



----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Behind the Web, Tips and Tricks for Web Development.
 
Well, that would explain why i couldn't get it to work. Too obvious.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top