Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I am trying to create readmore option in Textarea.

Here I can do it with div, but when I replace div with textarea, it just shows entire content in textarea without reamore option.

<body>
  <div class="container">  
    <h1>Demo</h1>
    <section id="demo">    
        <div>      
             <art>
            <div>
        <h2>Artisanal Narwahls</h2>
        <p>Salvia portland leggings banh mi fanny pack mixtape, authentic bushwick wes anderson intelligentsia artisan typewriter high life they sold out mixtape high life. Marfa ethnic wayfarers brooklyn keytar mixtape. Blue bottle shoreditch gluten-free, mixtape hoodie whatever pinterest viral twee fashion axe high life irony biodiesel tofu.</p>
        </div>    

         </art>
        </div>        
    </section>
  </div>
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
  <script src="readmore.js"></script>
<script>
  $('#info').readmore({
    moreLink: '<a href="#">More examples and options</a>',
    maxHeight: 190,
    afterToggle: function(trigger, element, more) {
      if(! more) { // The "Close" link was clicked
        $('html, body').animate( { scrollTop: element.offset().top }, {duration: 100 } );
      }
    }
  });

    $('art').readmore({maxHeight: 240});
  </script>

</body>

Here is my fiddle. : http://jsfiddle.net/VSscB/

But in fiddle it does not give readmore option though same code and script as in my page.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
143 views
Welcome To Ask or Share your Answers For Others

1 Answer

you haven't loaded jQuery in jsFiddle.. you can select jQuery from "Framework and extensions" drop down menu.. and you're code works fine... working link also..

(function($) {...} })(jQuery);

should be before..

$('#info').readmore({...});

because unlike your markup you posted in your question.. the readmore plugin is loaded after the $('#info').readmore({}); function in jsFiddle.. so you will get an error.. check your console..

although.. you cant' use textarea.. if you just want to edit the content... you can set the contenteditable attribute to true... inspecting. the readmore.js plugin.. i found this can be done by...

 $('.readmore-js-section').attr("contenteditable","true") ;

updated link


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...