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

  • SEARCH
  • Home
  • 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 8887567
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T21:50:27+00:00 2026-06-14T21:50:27+00:00

I found this code: link $(.show-more a).on(click, function() { var $this = $(this); var

  • 0

I found this code: link

$(".show-more a").on("click", function() {
var $this = $(this); 
var $content = $this.parent().prev("div.content");
var linkText = $this.text().toUpperCase();    

if(linkText === "SHOW MORE"){
    linkText = "Show less";
    $content.switchClass("hideContent", "showContent", 400);
} else {
    linkText = "Show more";
    $content.switchClass("showContent", "hideContent", 400);
};

$this.text(linkText);
});​

CSS:

    div.text-container {
    margin: 0 auto;
    width: 75%;    
}

.hideContent {
    overflow: hidden;
    line-height: 1em;
    height: 2em;
}

.showContent {
    line-height: 1em;
    height: auto;
}
.showContent{
    height: auto;
}

h1 {
    font-size: 24px;        
}
p {
    padding: 10px 0;
}
.show-more {
    padding: 10px 0;
    text-align: center;
}

​

It was exactly what I was looking for, but as you can see here, if you modify it (link), the “Show more” link is there if you have only one or two lines, and it is not needed in that case.
Thank you for your answers!

  • 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-14T21:50:28+00:00Added an answer on June 14, 2026 at 9:50 pm

    As your sample code was not fully working I decided to enhance one of my own samples I created in a post a while ago.

    DEMO – Show more/less and hide the link when not needed

    The demo shows the first text to have no link and the second to have a link. If you add a few more characters to the first text you see the link appear when you run the fiddle again.

    The idea is to double check the client vs the actual height and determine then if you want to show the link. Similar to the below.

    $(".show-more a").each(function() {
        var $link = $(this);
        var $content = $link.parent().prev("div.text-content");
    
        console.log($link);
    
        var visibleHeight = $content[0].clientHeight;
        var actualHide = $content[0].scrollHeight - 1; // -1 is needed in this example or you get a 1-line offset.
    
        console.log(actualHide);
        console.log(visibleHeight);
    
        if (actualHide > visibleHeight) {
            $link.show();
        } else {
            $link.hide();
        }
    });
    

    The demo is using the following HTML:

    <div class="text-container">
        <h1>Lorem ipsum dolor</h1>
        <div class="text-content short-text">
            Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut
            labore Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt
        </div>
        <div class="show-more">
            <a href="#">Show more</a>
        </div>
        </div>
    <div class="text-container">
        <h1>Lorem ipsum dolor</h1>
        <div class="text-content short-text">
            Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. 
            At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. 
            Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua.
        </div>
        <div class="show-more">
            <a href="#">Show more</a>
        </div>
    </div>​
    

    and the following basic CSS:

    div.text-container {
        margin: 0 auto;
        width: 75%;    
    }
    
    .text-content{
        line-height: 1em;
    }
    
    .short-text {
        overflow: hidden;
        height: 2em;
    }
    
    .full-text{
        height: auto;
    }
    
    h1 {
        font-size: 24px;        
    }
    
    .show-more {
        padding: 10px 0;
        text-align: center;
    }
    

    ​

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I found this link where I got this code: $(document).ready(function(){ //when a link in
i have a problem using the Catch Clipboard Events code found on this link
I've found a code which opens this link after logging in to google account
I found this code on the internetz, it checks the current page url; function
I found this code to get the image size on javascript: function getImgSize(imgSrc) {
i found this code -(NSString *) genRandStringLength: (int) len { NSMutableString *randomString = [NSMutableString
I found this code snippet to retrieve the title from a YouTube video and
I found this code in the internet and I modified it for my use,
i found this code: protected override void OnSourceInitialized(EventArgs e) { base.OnSourceInitialized(e); HwndSource hwndSource =
I found this code using Google. private int RandomNumber(int min, int max) { Random

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.