With a little side of applesauce...

Friday, August 24, 2012

Drupal - using JQuery in custom functions

For anyone this is getting the following error:

 Uncaught TypeError: Property '$' of object [object Window] is not a function

yet sees that jquery.js is being loaded before their custom javascript. You will need to wrap your jquery syntax a la:

function toggleSelectedWorkshop(id) {
    (function ($) {
        if ( $('#selectMe-'+id).is('.selectedWorkshop')) {
            $('#selectMe-'+id).removeClass('selectedWorkshop');
        } else {
            $('#selectMe-'+id).addClass('selectedWorkshop');
        }
    }(jQuery))
}

http://drupal.org/node/1003664#comment-4414248

No comments: