views:

56

answers:

2

I have started to convert a code on my site to jquery from mootols I would like to include jQuery instead of mootools and then write some functions I'm using in mootools to jQuery so I can use the exact same code. Some of the code I'm using I already converted is for example:

jQuery.fn.addEvent = jQuery.fn.bind; 

However I'm having a hard time doing these:

$some_node.getElement('.class'); //where $some_node is an element like $(.selector);
$some_node.addClass('class');
$some_node.fireEvent('focus');
_node.setProperty('disabled', 'disabled').addClass('disabled');
$btn_node.removeProperty('disabled').removeClass('disabled');

Is there something out there for this?

A: 

Surely the above would convert to:

$('.class').addClass('class');

$('.class').live("focus", function(e) {
     //Do something on focus
     //E.g. $(this).attr('disabled', 'disabled').addClass('disabled');
});

Or if you just wish to set the document focus on that element:

$('.class').focus();
MRW
+2  A: 

Assuming the $some_node is a jQuery object, then the function equivalent in jQuery would be

  • getElement('selector') should be find('selector').first(), as getElement in Mootools seems to return the first element, thus first is used to reduce the find result array back down to one.
  • addClass('class') is just... addClass('class'). Can't see why you would have trouble with this.
  • fireEvent('event') should be trigger('event')
  • setProperty('attribute', 'value') should be attr('attribute', 'value')
  • removeProperty('attribute') should be removeAttr('attribute')

Of course there almost certainly are subtle differences between the functions in both languages, most of which I cannot point out as I am unfamiliar with Mootools.

Yi Jiang