
July 28th, 2009, 11:51 AM
|
 |
Contributing User
|
|
Join Date: Apr 2007
Location: Galway
Posts: 1,029
Time spent in forums: 2 Weeks 6 Days 3 h 11 m 52 sec
Reputation Power: 4
|
|
|
Issue with DOM and removeChild
Ok i've got something i can work around but i like to understand things and not just leave them while i find another way, basicall im using DOM to create elements and set a hyperlink to remove them, it works in firefox but not in IE6/IE7, i think it might be because IE might not like the fact that the hyperlink doing the delete is inside the span its deleting, which firefox dosent care about, well any i have the sample below which you will see. I have hardcoded the exact same code for the first span delete which if you use firebug you will see is identical to the first dynamic function call...
if you have any questions, i would appreciate the feedback/help,
Code:
<!DOCTYPE html PUBLIC
"-//W3C//DTD XHTML 1.0 Transitional//EN"
"DTD/xhtml1-transitional.dtd" >
<html xmlns = "http://www.w3.org/1999/xhtml">
<head>
<script type="text/javascript">
function remIt(elm,bse) {
base = document.getElementById(bse);
elemt = document.getElementById(elm);
base.removeChild(elemt);
}
function create_Element() {
var num = document.getElementById('cnt');
var cnt = parseInt(num.value);
var spn = document.createElement('span');
spn.setAttribute('id','spn'+cnt);
var inp = document.createElement('input');
inp.setAttribute('type','text');
inp.setAttribute('id','txt' + cnt);
inp.setAttribute('value',cnt);
var rem = document.createElement('a');
rem.setAttribute('href','#');
//var cnt2 = cnt+1;
var strng = "remIt('spn"+cnt+"','test');return false;";
rem.setAttribute('onclick',strng);
var del = document.createTextNode("delete");
rem.appendChild(del);
var br = document.createElement('br');
spn.appendChild(inp);
spn.appendChild(rem);
spn.appendChild(br);
num.value = cnt+1;
div = document.getElementById('test');
div.appendChild(spn);
}
</script>
<title></title>
</head>
<body>
<input type="hidden" id="cnt" value="1" />
<a href="#" onclick="remIt('spn1','test');return false;">Delete 1st</a>
<br />
<a href="#" onclick="create_Element();return false;">Create</a>
<br />
<div id="test">
</div>
</body>
</html>
__________________
When I die, I want to go peacefully like my Grandfather did, in his sleep -- not screaming, like the passengers in his car.
|