document.getElementById("img1").addEventListener("click", function(event){
event.preventDefault()
});
I have tried the above JavaScript, which does disable the link, while retaining right and middle button click actions which is what I want.
However, I have many links, each with a dynamically created ID and I cannot figure out how to pass the ID to the above code.
I have tried the following:
HTML:
<a id="img' . $row["idImage"] . '" onClick="passID(this.id)" href="images/img01"><div></div></a>
JavaScript:
function passID(linkId) {
var imgid = linkId;
alert(imgid);
document.getElementById(imgid).addEventListener("click", function(event) {
event.preventDefault()
});
But it doesn't disable the link. I put an alert in and it does return the correct ID of the clicked link but does not disable it so I'm at a bit of a loss on how to proceed from here.