MooTools – Style Properties


MooTools – Style Properties


”;


MooTools provides some Special methods to set and get style property values for DOM elements. We use different style properties such as width, height, background color, font weight, font color, border, etc. By setting and getting different values to these style properties, we can present HTML elements in different styles.

Set and Get Style Properties

MooTools library contains different methods which are used to set or get the value of a particular style property or multiple style properties.

setStyle()

This method allows you to set the value for a single property of DOM element. This method will work on the selector object of a particular DOM element. Let us take an example that provides background color for div element. Take a look at the following code.

Example

<!DOCTYPE html>
<html>

   <head>
      <script type = "text/javascript" src = "MooTools-Core-1.6.0.js"></script>
      <script type = "text/javascript" src = "MooTools-More-1.6.0.js"></script>
      
      <script type = "text/javascript">
         window.addEvent(''domready'', function() {
            $(''body_wrap'').setStyle(''background-color'', ''#6B8E23'');
            $$(''.class_name'').setStyle(''background-color'', ''#FAEBD7'');
         });
      </script>
   </head>
   
   <body>
      <div id = "body_wrap">A</div>
      <div class = "class_name">B</div>
      <div class = "class_name">C</div>
      <div class = "class_name">D</div>
      <div class = "class_name">E</div>
   </body>
   
</html>

You will receive the following output −

Output