0

I've got few divs on my website - on the load I want some of them to be hidden, some shown. I am hiding the ones I don't want like this:

$(".divToHide").hide();

It works well in Chrome, Firefox, IE8 an Opera... It doesn't in IE6 (I haven't tested on previous version yet...) - when I load the page all the divs are hidden properly. When I click a link that makes one of them visible it appears correctly. The problems shows when I click on a different link that's supposed to hide the first div and show another. The text of the first div is hidden, but the image stays and obstructs the newly shown div. I'm pretty sure it's a bug - when I zoom in or out of the page the divs that were supposed to be hidden disappear suddenly - they're only visible when I load the page.

Is there a way around it?

EDIT: I'm using jQuery v1.3.2

EDIT: Unfortunately the solution of using addClass to add css class that states display: none doesn't really work - it seemed like it did at first, but the problem is still there.

UPDATE: The js file I wrote can be found here, while the html here. The problem I have is that when you go from one portfolio to the other, the image of the first one stays there obstructing the next, even though it should be hidden (text underneath changes correctly). Wrong disappears when you try to zoom in/out of the page.
I used to hide all portfolios using $("#divId").hide(), but as was pointed out below, I now use $(".classToHide").hide().

UPDATE: The problem is solved on IE8 - I forgot to include the standards mode declaration... However, on IE6 it's still the problem.

4

5 回答 5

3

您正在使用 ID 选择器隐藏多个 div?

尝试给这些 div 类“divToHide”,然后使用:

$(".divToHide").hide();

也许 IE8 以不同于其他浏览器的方式处理重复的 id。

于 2009-05-03T20:31:38.917 回答
2

Just a thought: you're not using an old (pre-IE8) version of jQuery, are you?

Edit: No, grycz is using the current version.

于 2009-05-03T20:14:24.810 回答
2

编辑:简化为使用 toggleClass()

您可以尝试手动执行此操作,例如切换一个名为“隐藏”的 CSS 类。它可能看起来像这样:

function myToggle(element_id)
{
    mydiv = $('#' + element_id);
    mydiv.toggleClass("hidden");;
}

您的 css 文件将具有:

.hidden
{
    display:none;
}

我还没有对此进行测试,但这是我想你想要考虑的一种解决方法,如果这确实是 jQuery/IE8 中的一个错误。

于 2009-05-03T20:26:18.993 回答
0

尝试

$("#divToHide").css('display:none');

于 2009-05-04T09:49:30.903 回答
0

Are you sure that hide() function call is even getting called on the page load? Try putting an alert('hi') right before that function call, and see if that happens in IE8.

于 2009-05-03T20:21:28.803 回答