La mia conoscenza del Javascript negli ultimi anni si è un pò offuscata, ma vediamo di studiarci queste due funzioncine così da non confondere il "mi funziona e basta" con il "mi funziona e so anche il perchè".
Con il getElementByID mi posiziono nel tag che ha come ID lga.
Con RemoveChild rimuovo il tag desiderato.
A questo punto hai da provare:
- document.createElement()
- document.createTextNode()
Ti posto un esempio preso dal web
Con il getElementByID mi posiziono nel tag che ha come ID lga.
Con RemoveChild rimuovo il tag desiderato.
A questo punto hai da provare:
- document.createElement()
- document.createTextNode()
Ti posto un esempio preso dal web
HTML:
<html>
<head>
<title> Add child elements of Div</title>
<script type="text/javascript">
function addChildElements()
{
var newdiv=document.createElement("div");
var newtext=document.createTextNode("Label div :");
var aTextBox=document.createElement('input');
aTextBox.type = 'text';
aTextBox.value = 'Input Element';
aTextBox.id = 'txt_cell_two_';
newdiv.appendChild(newtext); //append text to new div
newdiv.appendChild(aTextBox); //append text to new div
document.getElementById("test").appendChild(newdiv); //append new div to another
}
</script>
</head>
<body>
<input type="button" value="Add Child Element" onclick="addChildElements()"/>
<div id="test"></div>
</body>
</html>