下向きの矢印がクリックされたときにテキスト全体を表示する方法はわかりません。ここで私が試したのは、1つのテキストボックスだけで動作しますが、2つ以上を作ったときには動かないのですか?複数の場所でtoggleClass fuctionを使用する方法は?
それだけで1つのテキストボックスのために動作しますが、私はそれらの2以上を作るとき、それは仕事をdoesnt
body{
background-color: dimgray;
}
.box{
padding: 10px;
border-bottom: 0.1px solid #dadada;
width: 700px;
background-color: #fff;
}
.box-content{
height: 30px;
overflow: hidden;
transition: 0.3s;
}
.box-expand{
height: auto !important;
}
.box-opt{
float: right;
}
.box-opt a{
text-decoration: none;
font-size: 70%;
color: #646464;
display: inline-block;
padding: 5px;
<script src="https://use.fontawesome.com/e74aa8f5bb.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div class="box">
<div class="box-opt">
<a href="#" id="box-toggle"> <i class="fa fa-chevron-down" aria-hidden="true"></i> </a>
</div>
<p class="box-content" id="box-content">this is an awsome comment bout this post this is an awsome comment bout this posttis is 7 this is an awsome comment bout this post this is an awsome comment bout this posttis is 7 this is an awsome comment bout this post this is an awsome comment bout this posttis is 7 this is an awsome comment bout this post this is an awsome comment bout this posttis is 7 this is an awsome comment bout this post this is an awsome comment bout this posttis is 7 this is an awsome comment bout this post this is an awsome comment bout this posttis is 7 this is an awsome comment bout this post this is an awsome comment bout this posttis is 7 </p>
<script>
$("#box-toggle").click(function (e) {
e.preventDefault();
$(".box-content").toggleClass("box-expand");
});
</script>
ワークスONE?
ONEのdoesntのORK
body{
background-color: dimgray;
}
.box{
padding: 10px;
border-bottom: 0.1px solid #dadada;
width: 700px;
background-color: #fff;
margin: 10px;
}
.box-content{
height: 30px;
overflow: hidden;
transition: 0.3s;
}
.box-expand{
height: auto !important;
}
.box-opt{
float: right;
}
.box-opt a{
text-decoration: none;
font-size: 70%;
color: #646464;
display: inline-block;
padding: 5px;
<script src="https://use.fontawesome.com/e74aa8f5bb.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div class="box">
<div class="box-opt">
<a href="#" id="box-toggle"> <i class="fa fa-chevron-down" aria-hidden="true"></i> </a>
</div>
<p class="box-content" id="box-content">this is an awsome comment bout this post this is an awsome comment bout this posttis is 7 this is an awsome comment bout this post this is an awsome comment bout this posttis is 7 this is an awsome comment bout this post this is an awsome comment bout this posttis is 7 this is an awsome comment bout this post this is an awsome comment bout this posttis is 7 this is an awsome comment bout this post this is an awsome comment bout this posttis is 7 this is an awsome comment bout this post this is an awsome comment bout this posttis is 7 this is an awsome comment bout this post this is an awsome comment bout this posttis is 7 </p>
<script>
$("#box-toggle").click(function (e) {
e.preventDefault();
$(".box-content").toggleClass("box-expand");
});
</script>
</div><div class="box">
<div class="box-opt">
<a href="#" id="box-toggle"> <i class="fa fa-chevron-down" aria-hidden="true"></i> </a>
</div>
<p class="box-content" id="box-content">this is an awsome comment bout this post this is an awsome comment bout this posttis is 7 this is an awsome comment bout this post this is an awsome comment bout this posttis is 7 this is an awsome comment bout this post this is an awsome comment bout this posttis is 7 this is an awsome comment bout this post this is an awsome comment bout this posttis is 7 this is an awsome comment bout this post this is an awsome comment bout this posttis is 7 this is an awsome comment bout this post this is an awsome comment bout this posttis is 7 this is an awsome comment bout this post this is an awsome comment bout this posttis is 7 </p>
<script>
$("#box-toggle").click(function (e) {
e.preventDefault();
$(".box-content").toggleClass("box-expand");
});
</script>
</div><div class="box">
<div class="box-opt">
<a href="#" id="box-toggle"> <i class="fa fa-chevron-down" aria-hidden="true"></i> </a>
</div>
<p class="box-content" id="box-content">this is an awsome comment bout this post this is an awsome comment bout this posttis is 7 this is an awsome comment bout this post this is an awsome comment bout this posttis is 7 this is an awsome comment bout this post this is an awsome comment bout this posttis is 7 this is an awsome comment bout this post this is an awsome comment bout this posttis is 7 this is an awsome comment bout this post this is an awsome comment bout this posttis is 7 this is an awsome comment bout this post this is an awsome comment bout this posttis is 7 this is an awsome comment bout this post this is an awsome comment bout this posttis is 7 </p>
<script>
$("#box-toggle").click(function (e) {
e.preventDefault();
$(".box-content").toggleClass("box-expand");
});
</script>
</div><div class="box">
<div class="box-opt">
<a href="#" id="box-toggle"> <i class="fa fa-chevron-down" aria-hidden="true"></i> </a>
</div>
<p class="box-content" id="box-content">this is an awsome comment bout this post this is an awsome comment bout this posttis is 7 this is an awsome comment bout this post this is an awsome comment bout this posttis is 7 this is an awsome comment bout this post this is an awsome comment bout this posttis is 7 this is an awsome comment bout this post this is an awsome comment bout this posttis is 7 this is an awsome comment bout this post this is an awsome comment bout this posttis is 7 this is an awsome comment bout this post this is an awsome comment bout this posttis is 7 this is an awsome comment bout this post this is an awsome comment bout this posttis is 7 </p>
<script>
$("#box-toggle").click(function (e) {
e.preventDefault();
$(".box-content").toggleClass("box-expand");
});
</script>
</div>
IDは一意である必要があります。 DOMで 'box-toggle'を何度も使うべきではありません。また、クラスを切り替えるために '.box-content'の代わりに特定のセレクタが必要なので、各トグルの場所は独立しています。 –