|
|
Question : Replacing html element inside javascript
|
|
Hi All,
Requirement is inside javascript method hide existing select box and at the same place create new select box with one option in it. Use of innerhtml is not desired.
code which I have wrote looks like this.
function replaceElement() { var component = document.getElementById('elementName'); component.style.display="none"; var element = document.createElement("input"); element.setAttribute("name", "textfield1"); element.setAttribute("type", "text"); try{ component.getParent().addChild(element); // exception is thrown here. nosuchmethod. // how can I add the element here to my html.
}catch (e) { alert(e.name); alert(e.message); } }
Thanks in Advance.
|
Answer : Replacing html element inside javascript
|
|
Got it! Give this a try...
component.parentNode.appendChild(element);
|
|
|
|
|