Search code examples
jquerydrupal-7uikit

trigger UIkit notify component on page load instead of with button click - Drupal 7


Im looking to turn this function copied from the example page at getuikit.com from an event triggered by a button click to simply fire on page load. Im using drupal 7. The code below works if I load the data into a button and then click it, the notify component loads as intended. I would like to be able to load the notification as soon as the page loads.

$(function(){
        $("body").on("click", ".tralerts[data-message]", function(){
            $.UIkit.notify($(this).data());
        });
 })

Solution

  • In the page ready you may always do:

        $(function () {
            $(".tralerts[data-message]").trigger( "click" );
        });
    

    But, I assume your UIkit component is loaded after the page ready (i.e.: at window load). In this case you may use:

        $(window).on('load', function(e) {
           $(".tralerts[data-message]").trigger( "click" );
        })