Skip to main content

Mootools Basics - A Series

By Andrew Lawton – August 28, 2009
Andrew Lawton

How can you leverage a JavaScript framework to create a more exciting and dynamic community? follow this series to learn how.

Episode 1: Element Selection & Manipulation; Events

The IGLOO platform utilizes Mootools, a JavaCcript framework for a number of system elements (for example, at the bottom of this page, the "Subscribe" and "Email Link" use mootools to create the animation of the form "sliding" down when clicked). In this series, we will create a script that creates a "box" over a page that has html content inside of it.

First, we will go over some of the basic pieces of mootools that we will require to complete this project. For starters, let's learn how to get an element. To do this, we will use the dollar function ($). This function takes an element's id, and return the element. We will be able to manipulate that element however we wish.

for example, the element in example 1 (here) has an id of "myElement". To retrieve this, we will do the following:

var element = $('myElement');

this will retrieve the element with an id of "myElement", and assign that to the variable "element". With this variable, we can assign, or retrieve information about that element. for example, to get the text inside of that element, we can use the function get, example:

which will return "Hello World!". To change the text, we will use the set function, as the below example shows:

element.set('text', 'Hello Changed Text');

Before these functions will work, we will need to make sure that element has been loaded (an element cannot be retrieved until it is loaded into the DOM) before we manipulate it. To do this, we will use events, specifically the mootools event "domready", which loads when the DOM has been fully loaded, and elements are loaded in the DOM. to use this, we need to do the following:

window.addEvent('domready', function(){
    var element = $('myElement');
    element.set('text', 'Hello Changed Text');
});

or, in english: once the elements in the window have been loaded, get the "myElement" element, and then change the text inside the element to say "Hello Changed Text". In the next article, we will learn to create a modal box (Like this)

 

About the author

Andrew Lawton

Platform DeveloperIgloo Software

I am a person who should have this information indexed, so it can be searched. Here is something that should only show up for me: kcmcmcmcde

0 Comments

Would you like to comment?

You must be a member. Sign In if you are already a member.

  • 759 views
  • $obj.VersionIndex versions
  • 0 comments
  • 1 follower
     
Avg. Rating:
Post Date:
August 28, 2009
Posted By:
Andrew Lawton

About this channel

  • 33,662 views
  • 50 articles
  • 68 followers
     

Viewed 759 times