开发者

Alert firing on ready but action not working

On page load I want a div t开发者_运维技巧o be hidden. I attached an alert that is appearing but its not hiding the div.

Code:

$(function () {
   alert('test');
   $('#hide').hide();
});


<div id="hide">
  <ul>
    <li><a href="#">Facebook</a></li>
    <li><a href="#">Twitter</a></li>
    <li><a href="#">Diggs</a></li>
  </ul>
</div>


The script is running before the DOM has loaded, so $('#hide') doesn't exist yet.

Wrap your function like so:

$(document).ready(function() {
   $('#hide').hide();
});


It was a combination of javascript errors and actions being disabled. I was trying to make edits to a page made by another developer. Thanks for the suggestions though.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜