Trouble determining onclick's target
Posted
by pwseo
on Stack Overflow
See other posts from Stack Overflow
or by pwseo
Published on 2009-11-29T00:53:46Z
Indexed on
2010/04/12
0:03 UTC
Read the original article
Hit count: 256
JavaScript
|javascript-events
I've tried and tried... and I can't seem to make this work in IE (tested version 6) Can anybody help me? IE complains about an error but refuses to tell which error it is...
var a = document.getElementsByTagName("a");
for (i = 0; i < a.length; i++) {
if (a[i].getAttribute("class") == "info-link") {
a[i].onclick = function(e) {
e = e || window.event;
var target = e.srcElement || e.target;
var info = target.parentNode.getElementsByTagName("div")[0];
if (info.style.display == "none" || info.style.display == "") {
info.style.display = "block";
} else {
info.style.display = "none";
}
return false;
}
}
}
<div class="auxdata">
<a href="#" class="info-link">Esta questão possuí dados anexos. Clique para ver.</a>
<div style="display: none;" class="info-inner">
<!-- variable stuff here -->
</div>
</div>
© Stack Overflow or respective owner