Get and Set Element Attributes with MooTools

  • Avinash
  • 1
  • Sep 28, 2011
  • Web Development

I am going to show how to set and get attributes of the any elements like title, id, class, etc.

This methods are available from very first version of the MooTools because we can say these are the most used functions of the MooTools if you are playing with the DOM.

Set the Attributes

set() function is used to set the attributes of the element. Let’s see how to use it.

// below will set class to "new_class" $('id').set('class','new_class'); // Set the inner Text $('id').set('text','New Texts');
  // below will set class to "new_class"
  $('id').set('class','new_class');
 
  // Set the inner Text
  $('id').set('text','New Texts');

Get the Attributes

get() function is used to get the attributes of the elements. Let’s see how to use it.

// below will Get class $('id').get('class'); // Get the Title $('id').get('title');
  // below will Get class
  $('id').get('class');
 
  // Get the Title
  $('id').get('title');

Related Posts

Written by Avinash

Avinash Zala is leading various projects which deals with the various technology involved with the web. A combination of perfect technical and management skills. Avinash would like to chat with you and convert your imagination into the working system. You can get in touch with him on Facebook and Twitter.

View all posts by:

  • http://gregbabula.info Greg Babula

    This is just as easy as using attr in jQuery, thanks for sharing.