tags:

views:

1718

answers:

6

I had a nested div as I show below:

<div id="header"><div class="header-content">
 <div class="button"></div>
 <div id="menu"></div>
</div>
  <ul>
    <li></li>
  </ul>
</div>

Now my javascript code like that:

<script>
 $(".button").click(function(){
   $("#menu").css({
     position:"absolute",
     zIndex:50000,
     display:"block"
   });
 });
</script>

It's work fine in firefox but in IE 6 and IE 7 it's not above all. Any one had an experienced about this help me please!

+4  A: 

Exactly the same

var show = function(){
  var menu = document.getElementById("menu");
  menu.style.position = "absolute";
  menu.style.zIndex = "50000";
  menu.style.display = "block";
  menu.style.top = 0;
}

works absolutely fine for me without JQuery. For both IE6 and IE7. Unfortunately can't test with JQuery now.

Is this example the exact code you are using?

dasha salo
+1  A: 

The problem could be that your menu element is empty, and IE therefore collapses it so you can't see it. (At least with your example code, that could be a problem. If your markup doesn't really look like that, please show us what it really looks like...)

Try:

<div id="header">
    <div class="header-content">
        <div class="button">& nbsp;</div>
        <div id="menu">& nbsp;</div>
    </div>
    <ul>
        <li>& nbsp;</li>
    </ul>
</div>

EDIT: The spaces between & and nbsp; shouldn't be there, but SO wouldn't actually print out the code if I just wrote &nbsp;...

Tomas Lycken
He doesnt have an extra closing div. While his html is badly laid out / nested, it isnt missing a </div> I would change your answer before you get downvoted
Antony Carthy
Thanks for the heads up! I got it back there again, and fixed the indentation as well.
Tomas Lycken
+1  A: 

I would guess you're trying to put the div over a <select>, <iframe> or <embed> / <object> such as Flash.

This is a known bug in earlier IEs.
There is a hack to get around it by putting your div inside an iframe, but it's not pretty.

Greg
Not being able to control the z-index of Windowed elements in IE is documented behaviour: 'All windowed elements paint themselves on top of all windowless elements, despite the wishes of their container.' (http://support.microsoft.com/kb/177378)
Grant Wagner
Yup, it's a well documented bug...
Greg
A: 
<form action="ketqua.tintuc" name="myform">
  <div class="Search-text-box">
    <img src="http://xalo.vn/1.gif" onclick="return _e_(event,0)" />
    <input type="text" name="q" value="{query/@query}" text="{query/@query}" />
    <input id="hq" type="hidden" name="hq" value="{query/@hiddenquery}" />
    <div class="Search-menu">
      <xsl:choose>
        <xsl:when test="@category-label != ''">
          <xsl:value-of select="@category-label" />
        </xsl:when>
        <xsl:otherwise>
          Search all
        </xsl:otherwise>
      </xsl:choose>
    </div>
  </div>
  <div class="search-btn"></div>

  • Tìm tất cả

this all my real html code and below exactly javascript code:

$("#Search-header-menu").css({
      top: top,
      left:left,
      display:"block",
      background:"#fff"
    });
gacon
Greg I don't put anything in side iframe or something like that, and this all my code Tomas and Dasha. Thank both of you very much!
gacon
You can edit your original question to add code. Also, you refer to #Search-header-menu, but have no element with this ID. Do you mean "#Search-menu"?
outis
oh I'm sorry I mean thank all of you, sorry my English skill not good hope you can see that :(
gacon
+1  A: 

Your problem is probably CSS related, rather than javascript related. Explorer handles z-index child, parent, and sibling elements different from the other browsers.

This article on z-index I wrote a while ago may help you out.

Eystein
Nice writeup. Sorted out the exact problem I was having. I would set your z-index to 1000 if I could :D
Aidan
A: 

The answer above is likely correct - in IE css with positioning you'll likely have to set a z-index in the parent div (which I'm assuming is positioned relatively as well).

ScottE