javascript - Appending div inside another div -
I am trying to add an input box to a div and my code is as follows:
document. GetElementById ('location'). Appendbill ('& lt; div id = "' + lname + '" & gt; & lt; input placeholder =' 'please enter' 'type = "article" name = "new button" />
/>
I do not use the innerHTML + =
method Because my first created input box uses text to lose text content while adding new input box.
The above code is not working for me Is there a problem with the code? < / P>
Your code is completely incorrect: .appendChild ()
does not match the method as string
argument, it's a If the node element is
, then you should first create the element, and then add it to the parent. The correct code will be:
var container = document.getElementById (' Places'), children = document. CreateElement ('div'), input = document.createElement ('input'); Children.id = lname; Input.placeholder = 'Please enter'; Input.type = 'text'; Input.name = 'newbutton'; Children.appendChild (input); Container.appendChild (children);
Comments
Post a Comment