I am using jQuery Update to bump up the jQuery version on the front end, and keep the default 1.4 on the backend.

On a custom filter form on the home page, i use jQuery on, and wrap it in a behavior so it still works after an ajax event on that page.

The problem is that for some reason, when editing the page, and adding a new field collection row when Ajax is fired, the jQuery is being called, and an error happens because jQuery on did not exist in 1.4.

VM787:31 Uncaught TypeError: $(...).on is not a function

Steps to fix...

  1. I am using drupal_add_js but I check that if (!path_is_admin(current_path())) {//jQuery} to make sure it isnt called on the admin pages

  2. I am certain the JS is not on the admin pages, but after ajax, it is called because its in a behavior.

Is there a way to say which behaviors should run on the admin side, and which shouldnt?

1 Answer 1


Funny how sometimes you write out the question, and it makes you think about it in a different way!

The issue is that the behavior is obviously saved somewhere and called on an ajax event, EVEN if the js is not being called on that page! This was funny behavior to me, but the quick fix (maybe not the right fix) was to check the current path, and not run the JS inside that behavior if the path had "edit" in it.

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

        jQuery(document).ready(function() {

        var pathname = window.location.pathname;
            // If the page does NOT contain edit
            if (! (pathname.indexOf('edit') > -1) ) {

               // All of the JS stuff....



I will leave this question open for a few days as I would be interested to see if there's a better way of doing this. Ideally some way to control which behaviors are called on which pages?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.