Search code examples
javascriptjquerymootools

Making Mootools more into Jquery


I'm currently a Mootools beginner (started leanrning today). And I come from jQuery. I learned about Element.Implement.

I'm trying to add the .ready function from jquery to mootools.

Jquery .ready example:

$(document).ready(function(){
//Do stuff onload
});

I'm attempting to do this with mootools like this:

Element.implement({
ready: function(a){
       return this.addEvent('domready', a)
    }
});

But as I said. I'm a mootools beginner and I can't debug this.

I'm doing this because I like all the jquery functions. And Im used to the names of them. But I like that mootools has some advantages over jquery. And I know I could just use both. But thats to complicated


Solution

  • Just do this:

    function domready(domreadycode){
        window.addEvent('domready', domreadycode);
    }
    

    and use it like this:

    domready(function(){
        //code when document is ready
    });
    

    example:http://jsfiddle.net/U3XRM/