The problem I am having is the following:
I have a bunch of links that I need to assign onmousedown events to when the page loads, so I basically use a for loop to assign a function to all the events. The following is not an exact representation, but it'll do to explain what I'm talking about:
pageLinks = document.getElementsByTagName('a');
var loadPageContent = function () {
// Ajax is used here to retrieve a specific page's content from the DB and is displayed in the appropriate location.
// I also have an Ajax object set up, which I have glossed over for this example.
};
for (var i = 0; i < pageLinks.length; i++) {
pageLinks[i].onmousedown = loadPageContent;
}My original thinking was to place return false at the end of loadPageContent, but after testing it (and further thinking about it), I realized that that won't work. So now my question is, what can I do to suppress the link that is clicked on from being followed when Ajax is used?
Also, I refuse to write the following type of JS in the for loop, as it's just bad practice:
for (var i = 0; i < pageLinks.length; i++) {
pageLinks[i].onmousedown = function () {
loadPageContent(this);
return false;
};
}Likewise, I refuse to use inline JS mixed with HTML, so please do not even consider those as options. There must be a reasonable solution to this problem, which I am just overlooking.











