How to insert <li> element on <ul> using pure javascript

Posted by Damiii on Stack Overflow See other posts from Stack Overflow or by Damiii
Published on 2013-11-06T15:42:10Z Indexed on 2013/11/06 15:53 UTC
Read the original article Hit count: 192

Filed under:
|

I am having an issue with javascript and i don't know how to solve it ... Actually my code is working good with jsfiddle, but when i try to insert on my HTML page ,it simply doesnt work anymore ... What i want to, is to add the < li> on < ul> each time i tried to hit the button named "Add" !

HTML code:

....
<td width="50%" valign="top">
                    <b> SUPER: </b>
                    <ul id="ul">

                    </ul>
</td>
....
<input type="submit" value="Add" onclick="add()"/>
....

JavaScript code:

<script type="text/javascript">
                        function add(){
                            var ul = document.getElementById("ul");
                            var li = document.createElement("li");
                            li.innerHTML = "LoL";
                            ul.appendChild(li);
                    }
 </script>

The result with that code : it doesn't add anything on my HTML page when i try to hit the button... Thankfully,

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about html