tags:

views:

4549

answers:

2

Hi,

I'm trying to have a new layer appear above existing content on my site when a link/button is clicked. I am using jquery - but the code I have doesn't seem to work as expected.

Here is what I have:

 $(document).ready(function(){
  $("#button").click(function () {
  $("#showme").insertAfter("#bodytag")
  $("#showme").fadeIn(2000);
});

});

The effect I'm after is to have <div id="showme">...</div> appear directly after the #bodytag. <div id="showme">...</div> has a z-index higher than anything else on the site, so it should just appear above the content directly after the #bodytag.

Thanks for the assistance.

A: 

Make sure #showme has a position other than static.

eyelidlessness
+1  A: 

It would appear to me that to get the desired effect, the div you are inserting #showme into needs to be position: relative, and #showme should be position: absolute. Absolute positioning will take the element out of the document flow, allowing it to sit above the content.

Also, two tips - $() is a shortcut for $(document), and you can chain jQuery commands:

$().ready(function(){
  $("#button").click(function () {
    $("#showme").insertAfter("#bodytag").fadeIn(2000);
  });
});
tags2k
Thanks tags2k.The solution was as you describe. Adding position:absolute to the content I was inserting did it. Also - thanks for the shortcuts - I'm new to jquery so this was most appreciated.