开发者

Alert firing on ready but action not working

开发者 https://www.devze.com 2023-02-23 07:46 出处:网络
On page load I want a div t开发者_运维技巧o be hidden. I attached an alert that is appearing but its not hiding the div.

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

精彩评论

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