I am trying to understand the following code.
It appears to create the new element with no errors.
However, when I click to remove the element, I get this ‘warning’ message in the error console:
Timestamp: 5/8/12 4:40:44 PM
Warning: Element referenced by ID/NAME in the global scope. Use W3C standard document.getElementById() instead.
Source File: file:///Users/JMR/Desktop/Blank.html
Line: 1
Here is the code I’m using on a local computer (not on server yet).
Can anyone tell me how to eliminate the warning message in the error console?
As far as I can tell, I am using the getElementById function. ?
[code]
<html>
<head>
<title>Add / Remove Element</title>
<script type=”text/javascript”>
this.num = 1;
function addElement(){
var $top = document.getElementById(‘top’);
var newId = document.createElement(‘div’);
var id = ‘my’+this.num;
newId.setAttribute(‘id’, id );
var str = “<a href=” onclick=’removeThis( “+id +”);return false’>”;
str += “Remove this element: “+id+”</a>”;
newId.innerHTML = str;
$top.appendChild(newId);
this.num++;
}
function removeThis( id ){
var d = document.getElementById(‘top’);
d.removeChild(id);
}
</script>
</head>
<body>
<input type=”button” name=”button” value=”Add Element” onclick=”addElement()” />
<div id=”top” ></div>
</body>
</html>