Applied JS to Drupal theme doesn't work correctly, but it works fine outside Drupal Applied this JS http://jsfiddle.net/tbq8eo8b/10/ to webforms. As you can see in fiddle, it calculates total amount. When in Drupal, it gives 0 no matter what amounts you select, it always prints 0. What's wrong?

Drupal code:

(function ($) {
Drupal.behaviors.bartik = {
attach: function(context, settings) {

/*Add your js code here*/
    var $selects = $("select").change(function (e) {
        var total = 0;
        $selects.each(function() {
            var val = this.value.match(/\$(\d+)/);
            total += val ? +val[1] : 0;
        });
        $(".total").val(total);
    });

}

};
}(jQuery));


Also console prints:

TypeError: $ is not a function
$("select").change(function ()
}(jQuery));


should be

})(jQuery);


in your last line of code.