简体   繁体   中英

jQuery hide() not working (IE9)

I am making a div which should be hidden when the page loads, then visible once the user clicks a link. The code below works in FF / IE7 / IE8 but not in IE9, where the div is visible at all times ( without content ). Thanks in advance!

<script>
  $(document).ready(function() {
      $('#translateBoxen').hide();
      $('#translateToggle').click(function() {
         $('#translateBoxen').toggle(400);
         return false;
      });
  });
</script> // This is the jQuery code to hide and toggle the div //

<div style="width:200px;height:100px;position:absolute;"> // Just a holder that's needed for the site
  <a class="vitxtext" style="font-size:10px;" id="translateToggle" href="#">
      Translate
  </a>
  <div style="clear:both;"></div>
  <div id="translateBoxen">
       // BOX CONTENT //
  </div>
</div>

晚到派对,但尝试用display:none创建一个.hidden类,然后通过放入addClass('hidden')removeClass('hidden')而不是show / hide来隐藏/显示。

Why don't you hide the <div> with CSS? Just set to to display:none in your CSS, then when the toggle link is clicked for the first time it should be shown.

There is no reason why toggle() should not work in IE9, are you getting any script errors?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM