techhunter techhunter -4 years ago 85
CSS Question

Div inside fieldset using js

I created div inside another main div dynamicaly using js. Now I have created feildset and a legend . Now i want to add main div inside fieldset. I's not working.

var maindiv= document.createElement('div');
maindiv.setAttribute("id","TextBoxesGroup"+vl);
var secdiv=document.createElement('div');
secdiv.setAttribute("id","TextBoxDiv1"+vl)
maindiv.appendChild(secdiv);
var ipt=document.createElement("input");
ipt.setAttribute("type","text");
ipt.setAttribute("id","textbox1"+vl);
secdiv.appendChild(ipt);


for feildset:

var fld=document.createElement("fieldset");
fld.style.border="1px solid black";
var lgd=document.createElement("legend");
lgd.innerHTML=txt;
fld.appendChild(lgd);


Now i tried:
fld.appendChild(maindiv);
Bt it's not working. I there any there way of doing this?

Update:
Part of line i missed to update.

document.getElementById("updt").appendChild(maindiv);


The division inside another div displays properly. Only fieldset when I add it's not working.

Answer Source
Check this fiddle link [FIddle][1]. assign the fieldset to a parent element.
ex : i included the body as a parent for fieldset.


  [1]: https://jsfiddle.net/Abhilash1994/7Ltyc8zx/
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download