Chrome Giving 'Uncaught TypeError: addtocart.off is not a function' error

Looking at this page, I’m receiving an ‘Uncaught TypeError: addtocart.off is not a function’. I’m assuming it’s because of the jQuery version that is loading, but wanted to get another set of eyes to look at it.

The ‘addtocart.off’ is coming from this code:

if (typeof CustomfieldsForAll === "undefined") {

    var CustomfieldsForAll = {

            

        handleForms : function(forms) {

            forms.each(function() {

                var form = jQuery(this);

                var addtocart = form.find('.addtocart-button');

                addtocart.off('click');  <-------

                // addtocart.unbind();

                addtocart.click(function(e) {

                    var form = jQuery(this).parents('form');

                    var requiredChecked=CustomfieldsForAll.checkRequired(form);

                    if(requiredChecked)Virtuemart.sendtocart(form);

                    return false;

                });

            });

        },

Is it that, or is it because you have two items with the same class? The button, and a parent span both have the same class name.

The code you see is what Chrome is catching as the Uncaught Type Error. I’m not familiar with the two items of the same class, but I am curious on how this problem can be solved.

See the span and the input? Both have the same class. I don’t know if because there’s two, it’s causing an issue or not…

<span class="addtocart-button">
		<div class="product-price" id="productPrice35" style="opacity: 1;">
	<strong></strong><div class="PricevariantModification" style="display : none;">0</div><span class="price-crossed"></span><span class="Total-price">Total </span><div class="PricesalesPrice" style="display : block;"><span class="PricesalesPrice">$8.00</span></div></div>
		<input type="submit" name="addtocart" class="addtocart-button" value="Add to Cart" title="Add to Cart">
		</span>

That has nothing to do with the error. I went to this page: http://www.sitepoint.com/common-jquery-errors/, but didn’t see anything relevant to my case.

If the find returns multiple results then the off method would apply to each separately and not to the entire nodelist at once - producing exactly the error you are getting.

Try checking what addtocart contains after the find is assigned.

I wound up updating the jQuery code and a couple of other jQuery plugins code that I was using. That seemed to have done the trick.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.