Forum Moderators: open
Any ideas?
<html>
<head>
<title>DOM Scripting Test</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link id="stylelink" rel="stylesheet" type="text/css" href="jstest.css" media="screen" />
<script type="text/javascript">
var counter = 0;
function insertdiv(){
var newdiv = document.createElement('div');
var newpara = document.createElement('p');
var thetext = document.createTextNode("div"+counter);
newpara.appendChild(thetext);
newdiv.appendChild(newpara);
newdiv.setAttribute('class','floater')
newdiv.setAttribute('className','floater')
var idname = 'div'+counter;
newdiv.setAttribute('id',idname);
//newdiv.className=('floater')
document.getElementById('jstest').appendChild(newdiv);
counter++;
}
function deldiv(){
var formno = document.forms[0].elements[0].value;
var divno = 'div'+formno;
document.getElementById('jstest').removeChild(divno);
}
</script>
</head>
<body id="jstest">
<form id="frmDivNo">
<label for="txtDivNo">Enter Div Number</label>
<input id="txtDivNo" />
</form>
<a href="javascript:insertdiv()">click to insert div</a>
<a href="javascript:deldiv()">click to delete div</a>
</body>
</html>
<script type="text/javascript">
var counter = 0;
function insertdiv(){
var newdiv = document.createElement('div');
var newpara = document.createElement('p');
var thetext = document.createTextNode("div"+counter);
newpara.appendChild(thetext);
newdiv.appendChild(newpara);
newdiv.setAttribute('class','floater')
newdiv.setAttribute('className','floater')
var idname = 'div'+counter;
newdiv.setAttribute('id',idname);
document.getElementById('jstest').appendChild(newdiv);
counter++;
}
function deldiv(){
var formno = document.getElementsByTagName('div')[document.getElementsByTagName('div').length-1];
alert(formno.id)
document.getElementById('jstest').removeChild(formno);
}
</script>
function deldiv(){
var formno = document.forms[0].elements[0].value;
var divno = 'div'+formno;
if (!document.getElementById(divno))
{
alert('no div');
}
else
{
var oparent = document.getElementById('jstest');
var ochild = document.getElementById(divno);
oparent.removeChild(ochild);
}
}