How do you call a drupal behavior method from inside another behavior? My example below
(function ($) {
Drupal.behaviors.exampleOne = {
attach: function (context, settings) {
$('.example', context).click(function () {
$(this).next('ul').toggle('show');
});
}
exampleMethod: function (context) {
console.log('test');
}
};
// call exampleOne from inside exampleTwo
Drupal.behaviors.exampleTwo = {
attach: function (context, settings) {
$('.example-link', context).click(function () {
Drupal.behaviors.exampleOne.exampleMethod(context);
});
}
};
})(jQuery);
See how I try to call exampleMethod()
that belongs to behavior exampleOne inside behavior exampleTwo? I would think I can call it like that but I keep getting undefined
when I call it. Though if I call it like this console.log(Drupal.behaviors.exampleOne.exampleMethod);
, I get the function written out.