Forum Moderators: open
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>
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.