Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8159727
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T18:01:05+00:00 2026-06-06T18:01:05+00:00

Why is it in script 1 I can’t get hidden space to disappear when

  • 0

Why is it in script 1 I can’t get hidden space to disappear when i show or hide elements or even when I place “display: none” as styles? But in script 2 it works just fine? What am I doing wrong? Below is an image of the code in action:

enter image description here

Script 1:

<script>
    $(document).ready(function() {
        // if there are more than 4 posts, hide all after 4 and show the 'show more' link
        if($('a').length >= 4) {
            $('a').slice(4).hide();
            $("#showMore").show();

            // below display's 'show more' link. when clicked displays hidden comments and hides 'show more' link
            $("#showMore").click(function() {
                $('a').slice(4).show();
                $("#showMore").hide();
            });
        }
    });
</script>

<a>test </a><br>
<a>fed </a><br>
<a>fdes </a><br>
<a>grr </a><br>
<a>rerf </a><br>
<a style="display: none">dferf</a><br>
<a style="display: none">dferf</a><br>
<a style="display: none">dferf</a><br>
<a style="display: none">dferf</a><br>
<a style="display: none">dferf</a><br>
<a style="display: none">dferf</a><br>
<a style="display: none">dferf</a><br>
<a style="display: none">dferf</a><br>

<span id="showMore" href="javascript:void(0)" style="display: none">Show More</span>

Script 2:

<p id="example">This is an example of text that will be shown and hidden.</p>

<input type="button" value="Hide" onclick="$('#example').hide()" />
<input type="button" value="Show" onclick="$('#example').show()" />
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T18:01:06+00:00Added an answer on June 6, 2026 at 6:01 pm

    you can use gt selector:

    Select all elements at an index greater than index within the matched set.

    $('a:gt(4)').hide();
    

    instead of <br/> tag which adds extra space, you can use display: block for anchor tags:

    a {
       display: block
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is a script I can't get to work correctly. It's purpose is to
I'm maintaining a script that can get its input from various sources, and works
I need to make a proxy script that can access a page hidden behind
The JqGrid script can show a list of record loaded with ajax procedure. Example:
I don't get why my script can't find the gem that I just installed.
EDIT: The entire code and database creation script can be found from http://gitorious.org/scheator .
Here is a blog post from Kirk Munro that explains how a script can
Is there a script i can use to copy some particular sectors of my
In shell script how can i compare these kind of variable echo $du //170G
In shell script how can we compare (integer and floating point) ,(flaoting point and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.