1

I'm currently working on a project where I hide/show some table rows based on the contents of the table cells.

I'm using jQuery's each method to loop through the table rows, this works fine in all modern browsers except IE7.

This is my code:

$('li').click(function() {
    var listLetter = $(this).text();
    $("td").hide();
    $("tr").each(function(){ // this is where IE7 goes huh
        var cellLetter = $("td:first", this).text().substr(0,1);
        if (cellLetter == listLetter) {
            $('td', this).show();
        }
    })
});

Is there a way to make this work in IE7?

timkl
  • 3,299
  • 12
  • 57
  • 71
  • 2
    The ".each()" construct works fine in IE7. What exactly goes wrong for you? Are there JavaScript errors? – Pointy Feb 27 '11 at 20:55
  • Nothing happens - no JavaScript errors, the table row doesn't show. I'm working on a site that uses the EmulateIE7 meta tag, when I comment out the tag, it all works. – timkl Feb 27 '11 at 21:02
  • Working example here: http://timkjaerlange.com/foobar/stack-stuff/hide-table-row.html – timkl Feb 27 '11 at 21:02
  • 2
    "works fine in all modern browsers except IE7".... I would argue that IE7 is not a modern browser. :-) – Spudley Feb 27 '11 at 21:03
  • 2
    Since you're focused on only the first character of text, I'd try trimming whitespace in case IE is inserting some. `var cellLetter = $.trim( $("td:first", this).text() ).substr(0,1);` – user113716 Feb 27 '11 at 21:20
  • @patrick Didn't do the trick. Thx for the idea, though :) – timkl Feb 27 '11 at 21:28
  • @timki - a question: do the table cells start off invisible? In other words, do they start off with a style (either from a CSS file or from an inline "style" attribute) where "display" is "none"? – Pointy Feb 27 '11 at 21:32
  • @timki check my updated answer - I think I know what the problem is, though not the root cause. – Pointy Feb 27 '11 at 22:00
  • I think there's a superfluous space in your code. – Goran Feb 27 '11 at 22:19
  • @patrick dw you were right - the `
  • ` text has to be trimmed because IE thinks there's a space after it.
  • – Pointy Feb 27 '11 at 22:21
  • @Pointy: Well I was half right, which doesn't quite qualify as right. Good call on the other trim. I'm always happy when someone else finds a solution before I get around to firing up IE! ;o) – user113716 Feb 27 '11 at 22:45