Thursday, May 9, 2024
 Popular · Latest · Hot · Upcoming
85
rated 0 times [  91] [ 6]  / answers: 1 / hits: 49895  / 12 Years ago, tue, august 14, 2012, 12:00:00

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';
}}

More From » css

 Answers
23

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;
}}

[#83657] Monday, August 13, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
ernest

Total Points: 332
Total Questions: 92
Total Answers: 98

Location: Armenia
Member since Sat, Dec 31, 2022
1 Year ago
;