开发者

jQuery last-child throws exception in IE8

开发者 https://www.devze.com 2023-04-13 04:42 出处:网络
I have a table with 3 columns.The 3rd column contains only tags with which to sort the rows.On $(document).ready I use jQuery to hide the 3rd column (containing only tags) and add styling classes to t

I have a table with 3 columns. The 3rd column contains only tags with which to sort the rows. On $(document).ready I use jQuery to hide the 3rd column (containing only tags) and add styling classes to the other columns using

$(document).ready(function() {
$("#songListTable tr td:nth-child(3)").hide().width(0); 
$("#songListTable tr td:nth-child(1)").addClass("songTitle");
$("#songListTable tr td:nth-child(2)").addClass("songPerformer");
});

This works on all browsers.I added the .width(0) to make sure the hidden column did not take up any space in the layout.

Then I use a form select to send a value:

<form id="songSortForm" name="songSortForm" method="post" action="">
<select name="songSortSelect" id="songSortSelect" onChange=sortSongs(this.value)>

to a script to cycle through all rows in the column, check to see if the 3rd td in that row contains the value, and show or hide the entire row based on the result.

function sortSon开发者_如何学Pythongs (tagQuery) {
$("#songListTable tr").each(function() {
    $thisText= $(this).find("td:last-Child").html();
    $(this).show();

    if ($thisText.indexOf(tagQuery)>-1) {
    $(this).show();
    }
else {
    $(this).hide();
    } 
})
};

This works beautifully in all browsers but IE. IE developers tools are showing an exception thrown and not caught in the jQuery1.6.2 script (line 17, character 12370). However as I step through the script the error seems to be thrown every time I use "td:last-Child" in my sorting script. script breaks. last-Child throws no error in the (document).ready script, so it's probably an error in my own code, but I've been looking for 2 days to find an answer online.

The only style attached to anthying in the table is font-family, color, width, margin, and text-align.

ANY help would be GREATLY appreciated!!

You can see the test page at: http://donbryn.ipage.com/media.php (click on "song List").


I think that's because IE8 doesn't support :last-child selector, but just :first-child

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号