2

I need a jQuery script to load immediately before a certain block shows on my Drupal 8 front page. I'm trying to use the following but I get 'TypeError $ is not a function' in code inspector. Here's my script:

$(document).ready(function() {
  $("#slideshow").zAccordion({
        ...code...
  });
});

The problem is the first line. In Drupal 8 what is the preferred way to write this script to accomplish what I want?

0

1 Answer 1

4

You have to wrap the javascript to avoid namespace conflicts.

(function ($) {
  $(document).ready(function() {
    $("#slideshow").zAccordion({
        ...code...
    });
  });
})(jQuery);
0

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