0
        <!DOCTYPE HTML>
        <html>
          <head>
            <script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
            <script src="http://code.jquery.com/jquery-migrate-1.2.1.min.js"></script>

            <style>
              body {
                margin: 0px;
                padding: 0px;
              }
              #myCanvas
              {
                background-color: blue;
              }
              .garagedoorthumbnail:hover
              {
                border: 1px solid green;
              }
            </style>
          </head>
          <body>
            <canvas id="myCanvas" width="540" height="305"></canvas>
            <script>
            var canvas = document.getElementById('myCanvas');
            var context = canvas.getContext('2d');
            var imageObj = new Image();

            imageObj.onload = function() {
                context.drawImage(imageObj, 0, 0);
            };
            imageObj.src = 'backgroundgaragedoor.png';

            $( ".garagedoorthumbnail" ).click(function() {
                console.log("hello");
                alert( "Handler for .click() called." );
            });
            </script>
            <div id="doorgallary">
                <p class="garagedoorthumbnail" src="garagedoor-beadedpanel.png">aaa</p>
                <img class="garagedoorthumbnail"  src="garagedoor-beadedpanelclassic.png" />
                <img class="garagedoorthumbnail"  src="garagedoor-beadedpaneltrifold.png" />
                <img class="garagedoorthumbnail"  src="garagedoor-beadedpaneltrifoldstockton.png" />
            </div>
          </body>
        </html>

The click function is not firing at all. I changed one to a paragraph to see if it was maybe the element. I have used click many times but this time it is not firing and I don't see what is wrong yet...

1 Answer 1

6

You're attempting to bind handlers before the elements exist. Wrap your code in a DOM ready handler:

$(document).ready(function() {
    $(".garagedoorthumbnail").click(function() {
        console.log("hello");
        alert("Handler for .click() called.");
    });
});
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you for posting this.

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.