August 23, 2010

Always ensuring that div tag is at top of page using jquery

Question by Roland

I have a div tag <div id="customError">Error</div> I want this div tag to always appear at the top of the page using jquery, so with otherwords even if the page is scrollable I want it to be always visible and on top of the page almost like the stackoverflow notification bar. Is this possible using JQuery? I tried a number of things and it disappears when the page is scrolled down. Any help advise will be appreciated.

Answer by fantactuka

You can use css only:

#customError {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;

  /* IE6 */
  _position: absolute;
  _top: expression(document.getElementsByTagName("body")[0].scrollTop + "px");
}

Answer by Starx

use this

#customError { 
   position:fixed;
   top:0;
   left:0;
}

Author: Nabin Nepal (Starx)

Hello, I am Nabin Nepal and you can call me Starx. This is my blog where write about my life and my involvements. I am a Software Developer, A Cyclist and a Realist. I hope you will find my blog interesting. Follow me on Google+

...

Please fill the form - I will response as fast as I can!