Jquery plugin/scop question
I am a relative newbie when it comes to jquery; my question pertains to scope and perhaps to plugins if anyone has the patience to link me to something useful.
The code below works, however I must put the script in the same div for it to actually work. I can't move it to the top of the page, or, ideally, to another library/source file for the purposes of CMS integration/readability. Any pointers would be appreciated, thank you.
<a id="hide" href="#" style="z-index:20;">hide</a>
<a id="show" href="#" style="z-index:20;">show</a>
<div id="block" style="position:absolute;background:#fff;开发者_C百科width:450px;height:450px;">
</div>
<div id="myBox" style="width:450px;height:450px;" >
<ul id ="menuElem" class="CMSListMenuUL">
<li><a href="#">a</a></li>
<li><a href="#">b</a></li>
<li><a href="#">c</a></li>
</ul>
</div>
<script>
$("#show").click(function () {
$("#block").fadeOut(1000);
return false;
});
$("#hide").click(function () {
$("#block").fadeIn(1000);
return false;
});
</script>
Give this a try
<script>
$(document).ready(function () {
$("#show").click(function () {
$("#block").fadeOut(1000);
return false;
});
$("#hide").click(function () {
$("#block").fadeIn(1000);
return false;
});
});
</script>
This waits for the script to run until after the document is already loaded.
精彩评论