0

I want to pass the click action from a#click1 to a#click2. If I click a#click1, then the link http://www.google.com should be opened. How to do that?

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
    jQuery(document).ready(function(){
        $('a#click1').click(function() {
            $('a#click2').click();
        });
    });
</script>
<div id="wrap1">
    <div id="content1">
        <a id="click1" href="">click</a>
    </div>
</div>
<div id="wrap2">
    <div id="content2">
        <a id="click2" href="http://www.google.com">click</a>
    </div>
</div>
1
  • 1
    your example is working, whats exactly your problem? Commented Mar 22, 2011 at 12:27

3 Answers 3

1

I can't see why what you have done wouldn't work but if all you want to do is navigate to the 2nd anchors href, you could do:

jQuery(document).ready(function(){
    $('a#click1').click(function() {
        window.location = $('a#click2').attr("href");
    });     
});
Sign up to request clarification or add additional context in comments.

Comments

0

I belive this is only possible if you declare a click function for the second link like you did for the first. So this should actually work:

jQuery(document).ready(function() {
$('a#click2').click(function() {
                alert('clicked!');
            });  
            $('a#click1').click(function() {
                $('a#click2').click();
            });     
        });

It should also work for s right out of the box!

Comments

0

this works for me

$('a#click1').click(function () {
            $('a#click1').attr('href', $('a#click2').attr("href"));
        }); 

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.