MooTools Tip: Class.toElement

In: web resources

11 Jan 2010

Many of you may not know of a feature that’s baked into MooTools’ Class internals: Class.toElement. Class.toElement allows you to pass the $ (or document.id) method an instance of your class and the instance will be treated as an element.

The MooTools Class.toElement Usage

/* baking into the class */
var myClass = new Class({
	initialize: function(container,options) {
		this.container = $(container);
	}
	// .. lots more methods //
	toElement: function() {
		return this.container;
	}
});

/* usage */
var mc = new MyClass('wrapper');
$(mc).fade('out'); //fades the container out

This isn’t a groundbreaking piece of code but it’s just another example of the flexibility that MooTools affords its developers. Happy coding!

Don’t forget to follow me on Twitter and be sure to visit Script & Style for the best Javascript and CSS articles around!

Sponsor the David Walsh Blog and get your brand in front of several thousand users per day!

MooTools Tip: Class.toElement

Related posts:

  1. NSFW Blocker Using MooTools and CSS
  2. Create a Simple Slideshow Using MooTools, Part III: Creating a Class
  3. Create a Simple Slideshow Using MooTools
  4. MooTools Class Creation Tips
  5. Using Opacity to Show Focus with MooTools


Go to Source

2 Responses to MooTools Tip: Class.toElement

Avatar

Ichisumi

January 20th, 2010 at 4:02 pm

see if u can find anything helpful here about mobile updates. the mobile stuff is near the bottom ^_^

also, might this help?
If I turn Twitter off, will I still get Direct Messages?

Yes. You will receive direct messages if you send OFF only once; to disable direct messages, send OFF twice or change the settings in the device settings page. You will always receive a copy of your message on your web archive, and in your email if you set it up in your preferences.

Avatar

geoweeg

March 19th, 2010 at 8:56 pm

Ian V stole my thunder. He's right about this product. The beauty of it is that if it goes to a landfill it will begin to decompose the moment it gets wet or is exposed to direct sunlight.

Comment Form

About this blog

This blog delivers stylish and dynamic news for designers and web-developers on all subjects of design, ranging from: CSS, Ajax, Javascript, web design, graphics, typography, advertising & much more. Our goal is to help you communicate effectively on the web with an engaging website or functional interface.