Я не знаю, как сделать все текстовое шоу, когда нажата стрелка вниз. вот что я пробовал, он работает только для одного текстового поля, но когда я делаю 2 или более из них, он не работает?Как использовать toggleClass fuction в нескольких местах?
ТОТ, ЧТО РАБОТАЕТ
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>
это работает только для одного текстового поля, но когда я сделать 2 или более из них, он не работает?
ТОТ Doesnt ОРК
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 должен быть уникальным. Вы не должны использовать 'box-toggle' несколько раз в DOM. И вам также понадобится конкретный селектор вместо '.box-content' для переключения класса, так что каждое место переключения будет независимым. –