tags:

views:

222

answers:

2

this jQuery script works on firefox, it give alert. but it doesn't work in IE 7. have any idea what went wrong?

markup:

<td class="tdnotes">
  <a title="" class="notes" id="order-1" href="#">
   <!-- an image -->
  </a>         
  <div style="display: none;" id="wrap-order-1" class="thenotes">
   <!-- text area, input elements -->
  </div>
 </td>

script:

  $(function(){  

    $("a.notes").click(function() {
        alert($(this).siblings().attr("class"));
        // I have tried .next() but didn't work as well 
        // alert($(this).next().attr("class"));
        return false;
    }); 

  });
+1  A: 

Presumably because siblings() will get you a collection, so you'll need to loop over the matched elements:

$("a.notes").click(function() {
    $(this).siblings().each(function() {
        alert($(this).attr('class'));
    });
    return false;
});
karim79
+1  A: 

It works fine in both Firefox and IE7 - Here's a Working Demo with your code.

karim79 is right in that siblings() will get you a collection, but chaining attr() onto siblings() will get you the specified attribute of the first element in the matched set. Since <a> with class notes has only one sibling in this example, then this works fine for what is expected in this instance. If you wanted to get the class attributes of all siblings in the wrapped set then you would need to iterate over them in some way, most probably using each() or map()

Russ Cam
yes it works in IE7. turn out, there is something else that make this not working. thx
Anwar Chandra