Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
JavaScript
{for (var i = 0; i < obj.length - 1; i++) {
                                var rwdata = obj[i].split("|");
                                document.getElementById('dvMainChatbox').style.display = "";
                                var MainDiv = document.getElementById('dvMainChatbox');
                                var ChildDiv = document.createElement('DIV');
                                ChildDiv.setAttribute('id', 'div_' + rwdata[0] + '_' +             rwdata[1]
                                //ChildDiv.innerHTML = rwdata[1];
                                // ChildDiv.setAttribute("label", "id");
                                ChildDiv[i] = document.createElement('label');
                                //ChildDiv[i] = rwdata[i].innerText;
                                rwdata[i] = document.createTextNode(obj[i]);
                                ChildDiv[i].appendChild(rwdata[i]);
                                document.getElementById('DIV' + i).appendChild(obj[i]);
}
Posted
Updated 8-Apr-14 23:34pm
v2

1 solution

Solution:

XML
<script type="text/javascript">
    function addElement() {

        var ni = document.getElementById('myDiv');

        var numi = document.getElementById('theValue');

        var num = (document.getElementById('theValue').value - 1) + 2;

        numi.value = num;

        var newdiv = document.createElement('label');

        var divIdName = 'my' + num + 'label';

        newdiv.setAttribute('id', divIdName);

        newdiv.innerHTML = "Element Number ' + num + ' has been added with id = '"+divIdName+"'!";

        ni.appendChild(newdiv);

    }

</script>
</head>
<body>
<input type="hidden" value="0" id="theValue" />

<p><a href="javascript:;" onclick="addElement();">Add Some Elements</a></p>

<div id="myDiv"> </div>
</body>
</html>
 
Share this answer
 
Comments
Atul 10576159 9-Apr-14 6:21am    
hello sir,
I am working on chatbox module.So i hav shown each onlinne user with seperate dynamic div. I will try to making this module like facebook chat So plz help me...
Thanking you
Er. Puneet Goel 9-Apr-14 6:26am    
But this is the solution to what your question is. What You can do is close this question my marking is accepted and add new one with more details if required.
Atul 10576159 9-Apr-14 6:37am    
k sir...
Atul 10576159 9-Apr-14 6:44am    
I have also created that div runtime.... in which i have to create label.
Er. Puneet Goel 9-Apr-14 6:46am    
in such case if you want to add HTMl or Element from server side you can do that.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900