Drimgere
Drimgere

Reputation: 3

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;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>

Upvotes: 0

Views: 56

Answers (1)

mkly
mkly

Reputation: 2263

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.

Upvotes: 1

Related Questions