Forum Moderators: open

Message Too Old, No Replies

adding javascript:void(0) to list of links?

         

Fiasst

6:53 pm on Jul 30, 2007 (gmt 0)

10+ Year Member



Hi,

I'm having trouble with a list of links. On page load I'd like to add 'javascript:void(0)' to the href attribute of an unordered list of links. I've tried everything I can think of and have search the web.

I'd really appreciate some help!

Here's what I have so far:


window.onload = function () {
addhref();
}
function addhref() {
li=document.getElementsBySelector('#foliolist li a');
}

<ul id="foliolist">
<li><a href="">Item 1</a></li>
<li><a href="">Item 2</a></li>
</ul>

Fotiman

7:31 pm on Jul 30, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Maybe something like this: (haven't tested it)


function addhref() {
var foliolist = document.getElementById("foliolist");
var aList = foliolist.getElementsByTagName("a");
for (var i = 0; i < aList.length; i++) {
aList[i].href="javascript:void(0)";
}
}

However, there may be better ways of doing this (like attaching an onclick event handler to each of the links that stops the event.

Fiasst

8:57 pm on Jul 30, 2007 (gmt 0)

10+ Year Member



thats just teh ticket, thanks :)