1

no result occur when i click test1 of test2

<html>
<head>
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.min.js"></script>
    <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js"></script>

    <script type="text/javascript">
    $(".trigger").click(function(event){
        console.log("d");
    });
    </script>
</head>
<body>
    <a href="#" class="trigger">Test1</a>
    <a href="javascript:void(0)" class="trigger" >Test2</a>
</body>
</html>

1 Answer 1

7

You need to put the event registration in document.ready() so that the element you are trying to bind the event are ready to your script.

$(document).ready(function(){

  $(".trigger").click(function(event){
        console.log("d");
    });

});
Sign up to request clarification or add additional context in comments.

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.