Skip to main content

Cookiebot blocks native DOM events

Comments

2 comments

  • Danny Krämer

    I have the same problem. In my example it is a "change" event on a checkbox that is not working when cookiebot is active. Any solutions for this problem?

    0
  • Karl Bishop

    I didn't find a solution for jQuery ready functions but I worked around it using vanilla JS.

    I added this function to the top of my JS:

    // Taken from https://youmightnotneedjquery.com/#ready
    function ready(fn) {
    if (document.readyState != 'loading'){
      fn();
    } else {
      document.addEventListener('DOMContentLoaded', fn);
    }
    }
     
    Then I replaced all the jQuery 'ready' handlers:
    // Replace this:
    $(function () {
    // do stuff inside jQuery ready handler...
    });

    // With this:
    ready(function () {
    // do stuff inside vanilla ready handler...
    // other jQuery code seems to work fine here!
    });

     
    This is working for me, including checkbox 'change' events inside a vanilla ready handler like this:
    ready(function () {
    var myCheckbox = $('#myCheckbox');
    myCheckbox.on('change', function () {
    console.log('This should work!');
    });
    });
    1

Please sign in to leave a comment.