Web | This Site

Learn Prototype
Prototype Resources
Selected Reading
© 2011 TutorialsPoint.COM

| Home |  | References |  | Discussion Forums |  | About TP

# Prototype addClassName() Method

This method turns Adds a CSS class to element.

## Syntax:

    element.addClassName(className);

## Return Value:

- An HTML element in which CSS class is added

## Example:

    <html>
    <head>
    <title>Prototype examples</title>
    <script type="text/javascript"
       src="/javascript/prototype.js">
    </script>
    <script>

    function addClass(){
       node = $("firstDiv");
       node.addClassName("title");
    }
    </script>
    </head>

    <style type="text/css">
    .title{
        color:#36C;
        font-size:20px;
    }
    </style>
    <body>
       <div id="firstDiv">
          <p>This is first paragraph</p>
       </div>

       <br />
       <input type="button" value="Add Class"
                 onclick="addClass();"/>

    </body>
    </html>

To understand it in better way you can Try it yourself.

Advertisement

Online Image Processing

Indian Baby Names