Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Feb 2011
    Posts
    12
    Thanks
    1
    Thanked 1 Time in 1 Post

    Hiding a div (picture) and still holding its position

    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)
    Code:
    function previousEvent(i) {
            var k = new Number(i);
            if (index == 0) {
                $('#previous').hide();
            }
    
            else {
                $('#next').show();
                index = index - 1;
                eventSelected(rawDates[index], rawTime[index]);
    
            }
        }
    And in my html...the div properties:

    Code:
    <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>
                            <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>
                            </div>
    edit:
    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!

    Matt

  • #2
    GŁtkodierer
    Join Date
    Apr 2009
    Posts
    2,127
    Thanks
    1
    Thanked 426 Times in 424 Posts
    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'}).

  • Users who have thanked venegal for this post:

    leetvivi (02-04-2011)

  • #3
    New Coder
    Join Date
    Feb 2011
    Posts
    12
    Thanks
    1
    Thanked 1 Time in 1 Post
    venegal, I cannot thank you enough!
    I was literally ripping my hair out over this easy one liner of code

    Thanks!!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •