Question

I keep getting an error in my jquery file: "Uncaught TypeError: Cannot call method 'click' of null (anonymous function) jQuery.extend.ready DOMContentLoaded - line 2

Jquery code:

  $(document).ready(function () {
      $(".leftImage a").click(function () {
          _gaq.push(['_trackEvent', 'sidebanner', 'click', $(this).attr('id'), 0, true]);
      }); //End Of SideBanners

      $("a[href$='.pdf'], area[href$='.pdf']").click(function () {
          if ($(this).attr("id")) {
              _gaq.push(['_trackEvent', 'pdf', 'click', $(this).attr('id'), 0, true]);
          } else {
              _gaq.push(['_trackEvent', 'pdf', 'click', $(this).attr('href'), 0, true]);
          }
      }); //End of pdfs mapping and non mapping

      $("a[href$='.zip']").click(function () {
          if ($(this).attr("id")) {
              _gaq.push(['_trackEvent', 'zipfile', 'download', $(this).attr('id'), 0, true]);
          } else {
              _gaq.push(['_trackEvent', 'zipfile', 'download', $(this).attr('href'), 0, true]);
          }
      }); //End of Zips

  });
Was it helpful?

Solution

Appears to be a conflict and you can solve by using the provided solution from http://api.jquery.com/jquery.noconflict/

jQuery.noConflict();

(function( $ ) {

  $(document).ready(function() {

        $(".leftImage a").click(function () {
            _gaq.push(['_trackEvent', 'sidebanner', 'click', $(this).attr('id'), 0, true]);
        }); //End Of SideBanners

        $("a[href$='.pdf'], area[href$='.pdf']").click(function () {
            if ($(this).attr("id")) {
                _gaq.push(['_trackEvent', 'pdf', 'click', $(this).attr('id'), 0, true]);
            } else {
                _gaq.push(['_trackEvent', 'pdf', 'click', $(this).attr('href'), 0, true]);
            }
        }); //End of pdfs mapping and non mapping

        $("a[href$='.zip']").click(function () {
            if ($(this).attr("id")) {
                _gaq.push(['_trackEvent', 'zipfile', 'download', $(this).attr('id'), 0, true]);
            } else {
                _gaq.push(['_trackEvent', 'zipfile', 'download', $(this).attr('href'), 0, true]);
            }
        }); //End of Zips

  });

})(jQuery);

Hope this helps!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top