View Full Version : Help with simple script

06-20-2008, 02:54 AM

I'm trying to fix a script that does a search for all links on a page and applies a display:none style to each one.

Here's what I have so far:






<a href="#">Remove this link</a>


alink = document.getElementsByTagName("a");
for (i=0; i <= alink.length; i++){
alink[i].style.display = "none";




When loading the script in IE it says:

alink[...].style is null or not an object

Does anyone know how to fix this?


06-20-2008, 03:49 AM
Instead of using javascript to search for every link and then hide each one, why not just use

<style type="text/css">
a:link {

However, the solution to your problem is:

for (i=0; i<=alink.length; i++){should be
for (i=0; i<alink.length; i++){

This actually threw an error in FF as well, but FF just plowed on ahead and rendered it anyway. IE has a habit of not executing that part at all if there is an error.

06-20-2008, 03:53 AM
You missed on adding a type attribute.
YOu need to declare alink and i.

I'm unaware where you want this be triggered, I suppose it's onload:

<script type="text/javascript">
var alink = document.getElementsByTagName('a');
for (var i=0; i <alink.length; i++)
alink[i].style.display = "none";

Highlighted are added.

Hope it helps.

binaryWeapon beat me.

06-25-2008, 09:01 PM
Thanks! It works perfectly now! :)