3

「Click Me」というテキストのdivがあります

および、表示テキスト オプションが制限された「P」タグ。jqueryで「Click me」をクリックしてTextを展開する方法はありますか。もう一度クリックして非表示にします。申し訳ありませんが、私は jQuery が苦手です。方法が見つかりませんでした。

ライブデモを見る 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;
 }

できればそれは素晴らしいことです。

4

1 に答える 1

3

これはtoggleClass(多くのオプションの1つ)を使用して行うことができます

$("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>

于 2013-06-28T18:44:15.817 に答える