views:

65

answers:

2

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>
A: 

IE before version 8 didn't do getAttribute('class') correctly, try reading the elements className property.

When you get past that, check how IE is reading the style property- it may capitalize style values that are lower-case in the source, like 'NONE', 'BLOCK'.

kennebec
A: 

As @Magnar said (+1), I would include jQuery, it has a simple to use

jQuery(elem OR "selector").click(function(e){}).

At the very least you can look inside its code and see how it does the click() handle

Fabiano PS