Link to home
Create AccountLog in
Avatar of brad0525
brad0525

asked on

href return false using javascript

I have two links

<a href="#" id="link1">Link1</a>
<a href="#" id="link2">Link2</a>

If I click on link1 I want link 2 to return false; and make the link a dead one...If I click on link2 I want link1 to return flase;

I want to use a javascript function to do so as I have multiple of these on a page..Any help is greatly appreciated..Thanks
ASKER CERTIFIED SOLUTION
Avatar of woepwobin
woepwobin

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
SOLUTION
Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Avatar of brad0525
brad0525

ASKER

yep that works, but if I want to make one of the links clickable again do I just change it to true?
SOLUTION
Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
A more verbose implementation. Clicking on link3 resets link1 and link2.

<script type="text/javascript">
<!--
    function falseclick(id) {
        document.getElementById(id).onclick = function() {
            alert('returning false');
            return false;
        }
    }
    function resetclick(id, otherid) {
        document.getElementById(id).onclick = function() {
            falseclick(otherid);
        }
    }
//-->
</script>

<a href="#" id="link1">Link1</a>
<a href="#" id="link2">Link2</a>
<a href="#" id="link3" onclick="resetclick('link1', 'link2'); resetclick('link2', 'link1');">Link3</a>

<script type="text/javascript">
<!--
    resetclick('link1', 'link2');
    resetclick('link2', 'link1');
//-->
</script>

Open in new window