View Full Version : Hiding a div (picture) and still holding its position

02-04-2011, 03:45 PM
Completely new to jQuery / Javascript, so sorry if I'm not very clear.

I'm currently trying to hide my navigation button when it hides the end of the list, right now I currently have:

Previous / Next (they are about the same anyways)

function previousEvent(i) {
var k = new Number(i);
if (index == 0) {

else {
index = index - 1;
eventSelected(rawDates[index], rawTime[index]);


And in my html...the div properties:

<div style="text-align:right;">
<div id="next" style="float:right;"><a onclick="javascript:nextEvent();">
<input type="image" name="next" src="images/SiteCollectionImages/MiniEvents/btn_Next.gif" alt="Next Event" title="Next Event"/></a>
<div id="previous" style="float:right; padding-right:2px;"><a onclick="javascript:previousEvent();">
<input type="image" name="previous" src="images/SiteCollectionImages/MiniEvents/btn_Previous.gif" alt="Previous Event" title="Previous Event"/></a>

Sorry forgot to explain, I'm trying to make it so when they click on next, and keep clicking until the end of the dataset, it will hold the previous button where it usually is. Instead right now it moves it over to where the "Next" button is. I figured there has to be a way to hide the button, but yet hold the position still.

Thanks in advance!


02-04-2011, 05:02 PM
If you give an element display: none (and that's what's actually happening inside hide()), it will be removed from the document flow, and the positions of other elements will change. If you want a hidden element to stay in the flow and retain its position, use visibility: hidden instead.

So, instead of $(yourElement).hide() you do $(yourElement).css({visibility: 'hidden'}), and instead of $(yourElement).show() you do $(yourElement).css({visibility: 'visible'}).

02-04-2011, 05:21 PM
venegal, I cannot thank you enough!
I was literally ripping my hair out over this easy one liner of code :)