asp.net mvc - Break a string and merge string in c# with show and hide options -


my requirement:

my string should break after words , @ place need place "+more" option. when user click "+more" need show entire text. after end of text need show "-hide". when user click "-hide" should show previous. means text "+more" option. can 1 this.

my code:

var fullstring= "string above 150 charecters here";  var compressedstring = totalnews.fullstring(150);  <div class="temphide">    @compressedstring   </div> <a class="show" id="@newsitem.applicationnewsid">+more</a>  var continues = fullstring.substring(150, totalnews.length - 150); <div style="display:none;" >  @fullstring &nbsp;&nbsp;<a class="hide">-hide</a> </div> 

script:

<script type="text/javascript">     $(document).ready(function () {         $('.show').click(function () {             $(this).next('div').slidetoggle();         });          $('.hide').click(function () {             $(this).parent().slideup();         });     });  </script> 

my problem:
here when click "+more" option showing "+more" "-hide". requirement when click "+more" need show fullstring "-hide" option. doing showing "+more" , "-hide". please can 1 this.

script:

$.fn.truncate = function(options) {     $(this).append('<span class="truncate_lh" style="display:none;">&nbsp;</span>')      var defaults = {         maxlines: 2,         moretext: 'more',         lesstext: 'less',         ellipsis: '...'     };      $.extend(options, {         lineheight: ($('.truncate_lh').css('height').replace('px', ''))     });     $.extend(options, {         maxheight: (options.maxlines * options.lineheight)     });     options = $.extend(defaults, options);      return this.each(function() {         var text = $(this);          if (text.height() > options.maxheight) {              text.css({                 'overflow': 'hidden',                 'height': options.maxheight + 'px'             });              var link = $('<a href="#" class="showhide">' + options.moretext + '</a>');             var wrapdiv = $('<div class="truncate_wrap" />');              text.wrap(wrapdiv);             text.after(link);              link.click(function() {                 if (link.text() == options.moretext) {                     link.text(options.lesstext);                     text.css('height', 'auto');                 } else {                     link.text(options.moretext);                     text.css('height', options.maxheight + 'px');                 }                 return false;             });         }     }); };  $().ready(function() {       $('.truncate').truncate( {           maxlines: 4     });   });  

view

<p class="truncate">//here text...</p> 

i have done of

http://jsfiddle.net/pjgzq/1/

visit link


Comments

Popular posts from this blog

Change php variable from jquery value using ajax (same page) -

Pull out data related to my apps from Android Play Store and iOS App Store -

How can I fetch data from a web server in an android application? -