Hi,
ich versuche für alle gefundenen Links Attribute ("onmouseover", "myFunction()") zu setzen.
Mit dem "Link 2" in diesem Beispiel funktioniert es, document.links liefert ja ein Array und muss bestimmt durch eine Schleife.
wie mache ich das?
HTML
<!DOCTYPE html>
<html>
<body>
<a href="/" title="Link #0">Link 0 </a><br>
<a href="/" title="Link #1">Link 1 </a><br>
<a href="/" title="Link #2">Link 2 </a><br>
<a href="/" title="Link #3">Link 3 </a><br>
<a href="/" title="Link #4">Link 4 </a><hr>
<script>
var links = document.links;
link2 = links[2];
link2.setAttribute("onmouseover", "myFunction()");
document.getElementsByTagName("a")[2].setAttribute("onmouseover", "myFunction()");
function myFunction() {
var t = document.createTextNode(" Hello World");
document.body.appendChild(t);
}
</script>
</body>
</html>
Alles anzeigen