Why this class assignment is not working in IE
        Posted  
        
            by 
                user550750
            
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by user550750
        
        
        
        Published on 2010-12-22T03:32:54Z
        Indexed on 
            2010/12/30
            5:54 UTC
        
        
        Read the original article
        Hit count: 331
        
JavaScript
|html
I've wrote this peice of code, this works fine in FF and Chrome but not in IE. Why is it?
<html>
    <header>
        <style type="text/css">
            .red{
                color: red;
            }
            .green{
                color: green;
            }
            .yellow{
                color: yellow;
            }
        </style>
    </header>
    <body>
        <div id="mydiv" style="height: 50px">Some contents</div>
        <div>
            <input type="radio" value="1" name="change" onclick="onClick(this)">Red</input> 
            <input type="radio" value="2" name="change" onclick="onClick(this)">Green</input> 
            <input type="radio" value="3" name="change" onclick="onClick(this)">Yellow</input> 
        </div>
        <script type="text/javascript">
            function onClick(el){
                var className = "";
                if(el.value == 1){
                    className = "red";
                }else if(el.value == 2){
                    className = "green";
                }else if(el.value == 3){
                    className = "yellow";
                }
                document.getElementById("mydiv").setAttribute("class", className);
            }
        </script>
    </body>
</html>
© Stack Overflow or respective owner