2
Contributors
3
Replies
4
Views
7 Years
Discussion Span
Last Post by tommytom70
0
<html>
    <head>
        <script type="text/javascript">
            function add() {            
                //count number of label
                var ctr = document.getElementsByTagName("label").length;
                ctr = ctr + 1;  

                var newElement = document.createElement('label');
                if(ctr !== 1) {
                    newElement.innerHTML = ', ' + ctr;
                } else {
                    newElement.innerHTML = ctr;
                }               
                document.getElementById("result").appendChild(newElement);
            }
        </script>
    </head>
    <body>
        <div>
            <input type="button" onclick="add()" value="Click me" />
        </div>
        <div id="result">            
        </div>
    </body>
</html>

Edited by mike_2000_17: Fixed formatting

Votes + Comments
This is clearly a homework assignment, and you just give him the code! Good job...
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.