mootoolscss-selectorsdomready

How to trigger an event in Mootools for a specific tag/element with a specific element ID?


How to trigger an event in Mootools for a specific tag/element with a specific element ID?

I have this:

<a href="youtube-clip...etc" rel="rokbox" id="video_popup" style="display: none;">Video</a>

This rel="rokbox" means that the element will be used by the Mootools RokBox modal box, but I've hidden the link.

Now, I've added this code:

window.onload = function() {
  if(document.readyState == 'complete') {
    // point of execution
    // here I want to trigger the "a" element I've wrote up before
  }
}

The code reaches until the "point of execution", when I set a basic alert, or whatsoever.


Solution

  • window.addEvent('domready', function() {
        $('video_popup').fireEvent('click');
    });
    

    Note the use addEvent/domready, which is the proper method to add a function which must execute once the page is ready.