Search code examples
getuikit

UIkit 3 Event is not working


I've been trying to add a tooltip to a button that only shown when certain conditions are met. I'm using [email protected]. According to the documentation, I should return false on beforeshow event.

UIkit.tooltip($element, { pos: 'top' });

$element.on('beforeshow', function(){
  return false;
});

if(condition){
 UIkit.tooltip($element).show();
}

The problem is that the beforeshow function never fires for some reason. I even tried this syntax mentioned in UIkit documentation:

UIkit.util.on($element, 'beforeshow', function () {
  return false;
});

Unfortunately, none of these methods worked for me.


Solution

  • the docs has some mistake, switcher has the same problem. the event is triggered on document not the target. you can use this syntax like this:

    UIkit.util.on(document, 'event', '#target-id', callback)
    

    the docs confused me a long time :(