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 9171023
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T16:06:25+00:00 2026-06-17T16:06:25+00:00

I have a div containing simple text. I should show only 3 lines of

  • 0

I have a div containing simple text. I should show only 3 lines of that text with showMore link. on clicking of showMore link I need to show all the text inside it with showLess link. Right now I am using overflow property to achieve this. But have a small problem that I should show "showMore" link immediately after the text. So how can I position the hyperlink inside the text?

My Code

 jQuery(document).ready(function () {
    jQuery('.showMore').click(function (event) {
        var contentDiv = jQuery('.contentDiv');
        contentDiv[0].style.height = 'auto';
        jQuery(event.target).hide();
        jQuery('.showLess').show();
    });
    jQuery('.showLess').click(function (event) {
        var contentDiv = jQuery('.contentDiv');
        var lineHeight = getLineHeight(contentDiv[0]);
        contentDiv[0].style.height = lineHeight * 3 + 'px';
        jQuery(event.target).hide();
        jQuery('.showMore').show();
    });
});


<!doctype html>
    <html>

    <body >
<div>
<div class = "contentDiv">
some content <br r1<br> r2<br> r3 <br> r4<br> r5
    </div>      
<a href = '#'  class = "showMore">Show More</a>
<a href = '#'  class = "showLess">Show Less</a>     
</div>
    </body>
    </html>


.contentDiv a {
    float : right;
 }
.contentDiv {
    overflow: hidden;
    height:3.6em;
    background:#ccc;
font-size : 12pt ;
    font-family :Courier;
 }
.showMore {
    float: right;
}
.showLess {
    position: relative;
    float: right;
    display : none;
margin-bottom : 5px
}
  • 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-17T16:06:26+00:00Added an answer on June 17, 2026 at 4:06 pm

    Just one of the million ways you could achieve this: fiddle

    HTML

    <div id="text">Lots of text..</div>
    <a href="#" id="showmore">Show More</a>
    <a href="#" id="showless">Show Less</a>
    

    CSS

    #text {height:55px;overflow:hidden;}
    #showless {display:none;}
    

    jQuery

    $('#showmore').on('click', function(e){
        $('#text').css('overflow', 'visible').css('height', 'auto');
        $('#showless').show();
        $(this).hide();
        e.preventDefault();
    });
    
    $('#showless').on('click', function(e){
        $('#text').css('overflow', 'hidden').css('height', '55px');
        $('#showmore').show();
        $(this).hide();
        e.preventDefault();
    });
    

    To position the ‘show more’ in the bottom right (as requested in your follow-up comment), put the <a> tag inside the div and position it absolutely. Fiddle

    HTML

    <div id="text">Lots of text..
        <a href="#" id="showmore">Show More</a>
    </div>
    <a href="#" id="showless">Show Less</a>
    

    CSS

    #text {height:55px;overflow:hidden;position:relative;}
    #showmore {position:absolute;bottom:0;right:0;background:#fff;padding-left:10px;}
    #showless{display:none;}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a div containing text which is inside another div displayed only under
I have a div containing a form. I use that div as a dialog
So I have a Div containing an iframe that I can Clone using JQuery.
I have a div element containing some text. When the user clicks a word
I have a div, containing text and a few links. I want to trigger
I have a basic page, with a div containing text, and a form to
I have a containing div that is constrained in its height and width. It
I have a DIV containing an image and a second DIV. The parent DIV
Hey so I have a div containing 3 links which have a background url
Continuing adopting my code to work with IE... I have a hidden div containing

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.