Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Click to Expand Text

Tags:

html

jquery

css

I have a div with a text "Click Me"

and a"P" tag with limited view text option . is there any way with jquery to click the "Click me " and Expand the Text . and again Click me to Hide . Sorry I am Not good at jQuery . Not finding way wo made it .

See live demo js Fiddle : http://jsfiddle.net/saifrahu28/7wKyj/

**HTML**
<div>Click me</div>

 <p>
  It is a long established fact that a reader
  will be distracted by the readable content of a 
  page when looking at its layout. The point of using Lorem Ipsum 
  is that it has a more-or-less normal distribution of letters, 
  as opposed to using 'Content here, content here',
  making it look like readable English. Many desktop publishing 
 <p>

CSS

p{
 overflow: hidden;
 text-overflow: ellipsis;
 display: block;
  white-space: nowrap;
  width:100px;
 }

If can that will be Great .

like image 466
S Raihan Avatar asked Mar 22 '26 03:03

S Raihan


1 Answers

This can be done using toggleClass (one of many options)

$("element").toggleClass("className");

$(function(){
    $("#clickMe").click(function(){
        $("#para").toggleClass("myClass");
    })
});
p{
     text-overflow: ellipsis;
     display: block;
      white-space: nowrap;
      width:100px;
}

.myClass
{
     overflow: hidden;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="clickMe">Click me</div>

<p id="para" class="myClass">
   It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English. Many desktop publishing 
<p>
like image 128
reggaemahn Avatar answered Mar 24 '26 16:03

reggaemahn



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!