English 中文(简体)
MooTools - Style Properties
  • 时间:2024-09-17

MooTools - Style Properties


Previous Page Next Page  

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 pbrary 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 span 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>
      <span id = "body_wrap">A</span>
      <span class = "class_name">B</span>
      <span class = "class_name">C</span>
      <span class = "class_name">D</span>
      <span class = "class_name">E</span>
   </body>
   
</html>

You will receive the following output −

Output