Menu
I want to add an onClick-event to a link I have, via a function.
It gets added, but the functionality does not appear to be working.
Any idea why?
function populateLinks(changeLink) {
document.getElementById(changeLink).onClick = “anotherFunction();”
}
<body id=”body”>
<a href=”#” onClick=”populateLinks(‘linkToBeChanged’)”>Populate the links</a><br>
<a href=”#” id=”linkToBeChanged”>My link</a>
<br><br>
<a href=”#” onClick=”alert(document.getElementById(‘body’).innerHTML);”>Click here to check that it is added</a>
</body>
// Michelle