Disabling onclick attribute with javascript
41,074
this should do the trick:
function showDiv(id)
{
if(id == "leftbutton"){
document.getElementById('orangediv').style.display = 'block';
document.getElementById('righttbutton').onclick = null;
}else{
document.getElementById('greendiv').style.display = 'block';
document.getElementById('leftbutton').onclick = null;
}}
Author by
ocat
Updated on July 24, 2022Comments
-
ocat almost 2 years
How do I disable the other onclick event once one of them has been activated. Both divs are set to display:none; in the CSS. This is probably really simple but I am new to programming.
HTML
<a id="leftbutton" href="#" onclick="showDiv(this.id); return false;">click me</a> <a id="righttbutton" href="#"onclick="showDiv(this.id); return false;">click me</a>
Javascript
function showDiv(id) { if(id == "leftbutton"){ document.getElementById('orangediv').style.display = 'block'; }else{ document.getElementById('greendiv').style.display = 'block'; }}
-
Dan Dascalescu almost 9 yearsDuplicate of Remove onclick event from img tag and technically of How can I remove an inline onclick attribute with a bookmarklet? as well.
-
-
ocat almost 12 yearsThank you. I tried this one first and it did what I was trying to do before.