Adding and removing a division using JavaScript
<pre><code>&lt;script type="text/javascript"&gt;
    var num=2;
    function addElement() 
    {
        var ni = document.getElementById('myDiv');
        var newdiv = document.createElement('div');
        var divIdName = 'my'+num+'Div';
        newdiv.setAttribute('id',divIdName);
        newdiv.innerHTML = 'Subject-' + num + '* :&lt;input type="text" id=textbox"' + num + '"/&gt;&lt;a href=\'#\' onclick=\'removeElement('+divIdName+')\'&gt;Remove&lt;/a&gt;';
        ni.appendChild(newdiv);
        num=num+1;
    } 

    function removeElement(divNum) 
    {
        alert(divNum.id);
        var d = document.getElementById('myDiv');
        var dd =document.getElementById(divNum.id);
        d.removeChild(dd);    
        for(var i=0;i&lt;d.childNodes.length;i++)
        {
            if(d.childNodes[i].id==divNum.id)
            {
                d.removeChild(d.childNodes[i]);    
            }
        }
    }
&lt;/script&gt;
</code></pre>

<p>It is working fine in Internet Explorer but in Firefox it is giving error like the element <code>my1Div</code> is not defined. Why is this happening and how can it be corrected?</p>

<p>Thanks.</p>
