0

I am debugging some jQuery code and have found that the section of code is not firing when clicked.

My HTML/PHP is:

$cartlink .= "<a class='add_to_cart button' data-id='{$product->id}' href='javascript:;' {$style}>{$label}</a>";

jQuery:

   <script>
        jQuery(window).on('click', 'a.add_to_cart.button', function() {
        console.log("batman");
    }); 
    </script>
4
  • Is the script after the HTML, are there any errors, (other generic debug questions), ? Commented Jun 27, 2014 at 21:26
  • 1
    Replace window with document Commented Jun 27, 2014 at 21:27
  • @tymeJV Yes it is and no theres not :) Commented Jun 27, 2014 at 21:27
  • @RahilWazir Can you post as an answer? You rock Commented Jun 27, 2014 at 21:29

1 Answer 1

2

You need to replace the window with document. Because window object doesn't contain DOM Nodes. You however can also do jQuery(window.document) to look for DOM Nodes.

JavaScript Window

The window object represents a window containing a DOM document; the document property points to the DOM document loaded in that window

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.