I am using jQuery\'s toggle() to show/hide table rows. It works fine in FireFox but does not work in IE 8.
.show()
/.hide()
work fine though
I had the same issue, but I found a nice workaround to make toggle
/slideToggle
work in all browsers.
<a id="myButton">Click</a>
<div id="myDiv" display="none">lorem ipsum .... text ....</div>
and now the JS:
jQuery("#myButton").click(function () {
var currentDisplay = jQuery("#myDiv").css("display"); // save the current Display value
jQuery(#myDiv).slideToggle("fast", function () { // lets do a nice slideToggle
// this code will run AFTER the sildeToggle is done
// so if slideToggle worked fine (in FF, chrome, ...) this will have no evect, since the value is already block or none
// but in case IE 8 runs this script, it will set the css display to the current value
if (currentDisplay == "none") {
jQuery(#myDiv).css('display', 'block');
}else {
jQuery(#myDiv).css('display', 'none');
}
});
return false;
});
The result is that slideToggle
works fine in all Browsers, except for IE8, in which will look a weird (messed up slide), but it will still work.
Upgrading to jQuery 1.4 fixes this, whilst I'm at it though, the only "fix" on this page which worked for me was Dough boy's answer:
$(document).ready(function() {
$(".readOnlyRow").hide();
$("#readOnlyRowsToggle").click(function() {
$(".readOnlyRow").toggle($('.readOnlyRow').css('display') == 'none');
});
});
$(document).ready(function() {
$(".readOnlyRow").hide();
$("#readOnlyRowsToggle").click(function() {
$(".readOnlyRow").toggle($('.readOnlyRow').css('display') == 'none');
});
});
There is a jQuery bug that IE8 causes everything to evaluate to true. Try above
I've noticed this as well. Likely you'll have to toggle a class on each td instead. Haven't tried this solution yet, so let me know!
For others - this is specific to IE8, not 6 or 7.
EDIT
Clearly you didn't try this as evidenced by the -1, as I just did with fine results (in my situation).
CSS
tr.hideme td { display: none }
JS
$("#view-advanced").click(function() {
$("tr.hideme td").toggle();
return false;
});
Remove the period from your <tr class=".readOnlyRow"><td>row</td></tr>
. The syntax for jQuery class selecting is to prepend it with a period, but you don't need it in your HTML code.
Just encountered this myself -- the easiest solution I've found is to check for:
:not(:hidden)
instead of
:visible
then act accordingly . .