Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

call a function on a created element 1

Status
Not open for further replies.

hunt00

Technical User
Mar 6, 2005
79
0
0
US
Trying to call a function on the created link. But the alert only shows when click on the Top Level.

Here is my js:

<script>
var theUL, theLi, theA;
function test() {
mystart = document.getElementById('testdiv');
for (var i=0; i<4; i++) {
theLi = document.createElement("li");
theA = document.createElement("a");
theA.id = "aid";
theLi.appendChild(theA);
mystart.appendChild(theLi);
theA.innerHTML = "test" + i;
theA.href = " + i;
document.getElementById('aid').onclick = alert('in'); //click on the each new link need to call a js function
}
}
</script>

My HTML:
<a href="#" onclick="test();">Top Level: </a><br>
<div id="testdiv"></div>


Thanks!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top