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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T07:21:30+00:00 2026-06-16T07:21:30+00:00

I am using below jQuery code to show/hide extra text on my web page

  • 0

I am using below jQuery code to show/hide extra text on my web page

jQuery.fn.shorten = function(settings) {
  var config = {
    showChars : 100,
    ellipsesText : "...",
    moreText : "more",
    lessText : "less"
  };

  if (settings) {
    $.extend(config, settings);
  }

  $('.morelink').live('click', function() {
    var $this = $(this);
    if ($this.hasClass('less')) {
      $this.removeClass('less');
      $this.html(config.moreText);
    } else {
      $this.addClass('less');
      $this.html(config.lessText);
    }
    $this.parent().prev().toggle();
    $this.prev().toggle();
    return false;
  });

  return this.each(function() {
    var $this = $(this);

    var content = $this.html();
    if (content.length > config.showChars) {
      var c = content.substr(0, config.showChars);
      var h = content.substr(config.showChars , content.length - config.showChars);
      var html = c + '<span class="moreellipses">' + config.ellipsesText + '&nbsp;</span><span   class="morecontent"><span>' + h + '</span>&nbsp;&nbsp;<a href="javascript://nop/" class="morelink">' +  config.moreText + '</a></span>';
      $this.html(html);
      $(".morecontent span").hide();
    }
  });
};

I am trying to apply it on below html:

    <div id="idcncinfobox" class="cncinfobox">             
        <div class="basic_cnc_info_layout">
            <span class="cncDesc more">asdjlkaj  lakjd alkjs dajskldj uiojlksjdf kljsdf jirj klcj sdklfj skldjf rijfkls dj fjsdklfjr iej kldjf sh fbasnmb fa slkjdf dfjkjri wsll l ljdklfjkljsd jskldfj jsdklfj jskldjf jklsdjfklsdj irjklsjdfir lskdjfir jklsjdfkl jsir jklsjdklfjrijklsjdklf</span>
            <dl>                        
                <dt>Aliases</dt><dt1>:</dt1><dd itemprop="actor" class="cncAliases more">fasdfsdfssdlkfjskldjf klsjlkdfjklsdj jsdklfj sjdkljf sjkldfdjkl ksdjl; fsdj f;sdkljf sdkl;fj sdkjkfjsdkljfklj jsdkl;fjklsdjfkljdkjfkljdklsjfkldjsklf</dd>
            </dl>                        
        </div>   
    </div>

I am using below js code to call jQuery function:

    $(document).ready(function() {
        $(".cncDesc").shorten({
             "showChars" : 50,
            "moreText"  : "See More",
            "lessText"  : "Less"
        });
        $(".cncAliases").shorten({
             "showChars" : 20,
            "moreText"  : "See More",
            "lessText"  : "Less"
        });
    });

As you see here I am trying to get show/hide effect on two elements on same page. And for some reason it’s not working. If I apply it on only one element, it works fine. I tried debugging it and found that when I am applying it on two elements, it goes into ‘Click’ function twice and ends up un-doing the effect.

I have created a Fiddle here http://jsfiddle.net/RzB7E/4/

  • 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-16T07:21:31+00:00Added an answer on June 16, 2026 at 7:21 am

    I think you can just change this line

    $('.morelink').live('click', function() {
    

    to

    $(this).find('.morelink').live('click', function() {
    

    as you can see here: http://jsfiddle.net/RzB7E/7/

    When you bind to a click event via a class, you bind too all clicks for all elements of that class. The change above specifies the specific .morelink to apply the click to.

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

Sidebar

Related Questions

I am using below code to show jquery dialog, its working perfectly, Sub OpenDialog(ByVal
I am using the below jquery code to call a ajax function in my
I am using jquery datepicker, please see below code $(document).ready(function() { $(.txtDate).datepicker({ showOn: 'button',
i am adding collection of radio buttons to my page using jQuery below $(document).ready(function()
I'm using the below code to show/hide a nav and its children. It is
I am using jquery addClass code to show/hide elements when rolling over a div.
I'm using the jQuery code below to launch an overlay div and it works
I am using the below code to initialise a jQuery FullCalendar. However, not all
I am new to jquery ! I am using the code below to insert
I am using jquery to create a custom dropdown with the code below. I

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.