vendredi 11 septembre 2015

dynamically create div and into a static div

On click of button i am trying to create one div and try to append static div into that and this is giving error.

Uncaught TypeError: elm.appendChild is not a function.

    <script>
        function s()
        {
            var elm = '<div' +
                'style="background-color:orange;height:125px;width:75px;"'+
                '</div>';           
            var x=document.getElementById("ss")         
            elm.appendChild(x);         
        }
    </script>       

    <div id="ss">
        <ul>
            <li style="background-color:grey;">
                <h2 class="wheater_CityName">Mumbai</h2><br><br>
                    <div style= 
                        "margin-left: 30%;
                        margin-top: -21%;"
                    >
                    </div>
                    <hr style= "margin-top: -83px; ">                   
            </li>
            <li>sad</li>
            <li>as</li>             
        </ul>
    </div>    
    <input type="button" value="ss" onclick="s()"/>



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire