javascript hide/show fails in ie8
I have the following javascript
开发者_开发技巧function hide(id)
{
var ele = document.getElementById(id);
if ((ele.style.display == 'none') || (ele.style.display == '')) {
try{
ele.style.display = 'table-row';
}
catch (e)
{
ele.style.display='block';
}}
else {ele.style.display = 'none';}
}
which works in ie7, chrome, ff, but fails in ie8
I have to get it to work in ie8 even if it fails in chrome or ff.
I believe the issue is 'ele.style.display = 'table-row'
any ideas? thanks in advance
Not sure what you are experiencing as a failure in IE8, but you might change in your if
this:
ele.style.display == ''
to this:
ele.style.display == undefined
Why don't you use:
function toggle(id) {
var el = document.getElementById(id);
el.style.display = (el.style.display == "none" || el.style.display == "") ? "block" : "none";
}
精彩评论