Web Development

Get and Set Element Attributes with MooTools

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

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

[cc lang=”javascript”]
// below will set class to “new_class”
$(‘id’).set(‘class’,’new_class’);

// Set the inner Text
$(‘id’).set(‘text’,’New Texts’);
[/cc]

Get the Attributes

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

[cc lang=”javascript”]
// below will Get class
$(‘id’).get(‘class’);

// Get the Title
$(‘id’).get(‘title’);
[/cc]

Shares:

Leave a Reply

Your email address will not be published. Required fields are marked *