2017-10-12 90 views
-1

我有一段很長的內容,只想顯示一部分內容,當用戶點擊'閱讀更多'時,我想要顯示整個內容和將按鈕從「閱讀更多」更改爲「更少閱讀」,同樣從「閱讀更少」更改爲「閱讀更多」。我怎樣才能做到這一點? 我重視我下面的代碼,每按一次按鈕,我想在兩個功能之間切換

$(document).ready(function(){ 
 
    $("#click-me").on("click", function(){ 
 
    $(this).html("Read Less"); 
 
    $(".content").css("overflow","auto"); 
 
    $(".content").css("height","auto"); 
 
    }); 
 
});
.card{ 
 
    border: 1px solid black; 
 
    margin: 10px; 
 
    padding: 20px; 
 
} 
 
.content{ 
 
    overflow: hidden; 
 
    height: 40px; 
 
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<div class="card"> 
 
    <div class="content"> 
 
    Game of Thrones is an American fantasy drama television series created by David Benioff and D. B. Weiss. It is an adaptation of A Song of Ice and Fire, George R. R. Martin's series of fantasy novels, the first of which is A Game of Thrones. It is filmed in Belfast and elsewhere in the United Kingdom, Canada, Croatia, Iceland, Malta, Morocco, Spain, and the United States. The series premiered on HBO in the United States on April 17, 2011, and its seventh season ended on August 27, 2017. The series will conclude with its eighth season premiering either in 2018 or 2019.[1] 
 

 
Set on the fictional continents of Westeros and Essos, Game of Thrones has several plot lines and a large ensemble cast but centers on three primary story arcs. The first story arc centers on the Iron Throne of the Seven Kingdoms and follows a web of alliances and conflicts among the dynastic noble families either vying to claim the throne or fighting for independence from the throne. The second story arc focuses on the last descendant of the realm's deposed ruling dynasty, exiled and plotting a return to the throne. The third story arc centers on the longstanding brotherhood charged with defending the realm against the ancient threats of the fierce peoples and legendary creatures that lie far north, and an impending winter that threatens the realm.Game of Thrones has attracted record viewership on HBO and has a broad, active, international fan base. It has been acclaimed by critics, particularly for its acting, complex characters, story, scope, and production values, although its frequent use of nudity and violence (including sexual violence) has been criticized. The series has received 38 Primetime Emmy Awards, including Outstanding Drama Series in 2015 and 2016, more than any other primetime scripted television series. Its other awards and nominations include three Hugo Awards for Best Dramatic Presentation (2012–2014), a 2011 Peabody Award, and four nominations for the Golden Globe Award for Best Television Series – Drama (2012 and 2015–2017). Of the ensemble cast, Peter Dinklage has won two Primetime Emmy Awards for Outstanding Supporting Actor in a Drama Series (2011 and 2015) and the Golden Globe Award for Best Supporting Actor – Series, Miniseries or Television Film (2012) for his performance as Tyrion Lannister. Lena Headey, Emilia Clarke, Kit Harington, Maisie Williams, Diana Rigg, and Max von Sydow have also received Primetime Emmy Award nominations for their performances in the series. 
 
    </div> 
 
    <button id="click-me">Read More</button> 
 
</div>

現在,我能夠從「更多」切換到「讀少」,但我沒有得到關於如何從「讀開關再次'閱讀更多'。

編輯:

如果我有多個內容展示,然後我想更多的和讀之間切換閱讀少。我在下面附加了我的代碼,我使用'this'對象來訪問當前對象,但沒有得到如何訪問只有該元素的內容。

$(document).ready(function(){ 
 
    var readMore=true; 
 
    $(".more-less").on("click", function(){ 
 
    var txt=$(this).html(); 
 
    console.log($(this)); 
 
    if(readMore){ 
 
    $(this).html("Read Less"); 
 
    $('.content').css("overflow","auto"); 
 
    $(this).css("height","auto"); 
 
     readMore=false; 
 
    }else{ 
 
    $(this).html("Read More..."); 
 
    $('.content').css("overflow","hidden"); 
 
    $(this).css("height","40px");  
 
     readMore=true; 
 
    } 
 
    }); 
 
});
.card{ 
 
    border: 1px solid black; 
 
    margin: 10px; 
 
    padding: 20px; 
 
} 
 
.content{ 
 
    overflow: hidden; 
 
    height: 40px; 
 
} 
 
.more-less{ 
 
    text-decoration: none; 
 
    font-weight: bold; 
 
}
<div class="card"> 
 
    <div class="content"> 
 
    Game of Thrones is an American fantasy drama television series created by David Benioff and D. B. Weiss. It is an adaptation of A Song of Ice and Fire, George R. R. Martin's series of fantasy novels, the first of which is A Game of Thrones. It is filmed in Belfast and elsewhere in the United Kingdom, Canada, Croatia, Iceland, Malta, Morocco, Spain, and the United States. The series premiered on HBO in the United States on April 17, 2011, and its seventh season ended on August 27, 2017. The series will conclude with its eighth season premiering either in 2018 or 2019.[1] 
 

 
Set on the fictional continents of Westeros and Essos, Game of Thrones has several plot lines and a large ensemble cast but centers on three primary story arcs. The first story arc centers on the Iron Throne of the Seven Kingdoms and follows a web of alliances and conflicts among the dynastic noble families either vying to claim the throne or fighting for independence from the throne. The second story arc focuses on the last descendant of the realm's deposed ruling dynasty, exiled and plotting a return to the throne. The third story arc centers on the longstanding brotherhood charged with defending the realm against the ancient threats of the fierce peoples and legendary creatures that lie far north, and an impending winter that threatens the realm.Game of Thrones has attracted record viewership on HBO and has a broad, active, international fan base. It has been acclaimed by critics, particularly for its acting, complex characters, story, scope, and production values, although its frequent use of nudity and violence (including sexual violence) has been criticized. The series has received 38 Primetime Emmy Awards, including Outstanding Drama Series in 2015 and 2016, more than any other primetime scripted television series. Its other awards and nominations include three Hugo Awards for Best Dramatic Presentation (2012–2014), a 2011 Peabody Award, and four nominations for the Golden Globe Award for Best Television Series – Drama (2012 and 2015–2017). Of the ensemble cast, Peter Dinklage has won two Primetime Emmy Awards for Outstanding Supporting Actor in a Drama Series (2011 and 2015) and the Golden Globe Award for Best Supporting Actor – Series, Miniseries or Television Film (2012) for his performance as Tyrion Lannister. Lena Headey, Emilia Clarke, Kit Harington, Maisie Williams, Diana Rigg, and Max von Sydow have also received Primetime Emmy Award nominations for their performances in the series. 
 
    </div> 
 
    <a href="#" class="more-less">Read More...</a> 
 
</div> 
 
<div class="card"> 
 
    <div class="content"> 
 
    Game of Thrones is an American fantasy drama television series created by David Benioff and D. B. Weiss. It is an adaptation of A Song of Ice and Fire, George R. R. Martin's series of fantasy novels, the first of which is A Game of Thrones. It is filmed in Belfast and elsewhere in the United Kingdom, Canada, Croatia, Iceland, Malta, Morocco, Spain, and the United States. The series premiered on HBO in the United States on April 17, 2011, and its seventh season ended on August 27, 2017. The series will conclude with its eighth season premiering either in 2018 or 2019.[1] 
 

 
Set on the fictional continents of Westeros and Essos, Game of Thrones has several plot lines and a large ensemble cast but centers on three primary story arcs. The first story arc centers on the Iron Throne of the Seven Kingdoms and follows a web of alliances and conflicts among the dynastic noble families either vying to claim the throne or fighting for independence from the throne. The second story arc focuses on the last descendant of the realm's deposed ruling dynasty, exiled and plotting a return to the throne. The third story arc centers on the longstanding brotherhood charged with defending the realm against the ancient threats of the fierce peoples and legendary creatures that lie far north, and an impending winter that threatens the realm.Game of Thrones has attracted record viewership on HBO and has a broad, active, international fan base. It has been acclaimed by critics, particularly for its acting, complex characters, story, scope, and production values, although its frequent use of nudity and violence (including sexual violence) has been criticized. The series has received 38 Primetime Emmy Awards, including Outstanding Drama Series in 2015 and 2016, more than any other primetime scripted television series. Its other awards and nominations include three Hugo Awards for Best Dramatic Presentation (2012–2014), a 2011 Peabody Award, and four nominations for the Golden Globe Award for Best Television Series – Drama (2012 and 2015–2017). Of the ensemble cast, Peter Dinklage has won two Primetime Emmy Awards for Outstanding Supporting Actor in a Drama Series (2011 and 2015) and the Golden Globe Award for Best Supporting Actor – Series, Miniseries or Television Film (2012) for his performance as Tyrion Lannister. Lena Headey, Emilia Clarke, Kit Harington, Maisie Williams, Diana Rigg, and Max von Sydow have also received Primetime Emmy Award nominations for their performances in the series. 
 
    </div> 
 
    <a href="#" class="more-less">Read More...</a> 
 
</div>

謝謝您的回答。

回答

0

$(document).ready(function(){ 
 
    var readMore=true; 
 
    $(".more-less").on("click", function(){ 
 
    var txt=$(this).html(); 
 
    console.log($(this)); 
 
    if(readMore){ 
 
    $(this).html("Read Less"); 
 
    $(this).parent().find('.content').css("overflow","auto"); 
 
    $(this).css("height","auto"); 
 
     readMore=false; 
 
    }else{ 
 
    $(this).html("Read More..."); 
 
    $(this).parent().find('.content').css("overflow","hidden"); 
 
    $(this).css("height","40px");  
 
     readMore=true; 
 
    } 
 
    }); 
 
});
.card{ 
 
    border: 1px solid black; 
 
    margin: 10px; 
 
    padding: 20px; 
 
} 
 
.content{ 
 
    overflow: hidden; 
 
    height: 40px; 
 
} 
 
.more-less{ 
 
    text-decoration: none; 
 
    font-weight: bold; 
 
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<div class="card"> 
 
    <div class="content"> 
 
    Game of Thrones is an American fantasy drama television series created by David Benioff and D. B. Weiss. It is an adaptation of A Song of Ice and Fire, George R. R. Martin's series of fantasy novels, the first of which is A Game of Thrones. It is filmed in Belfast and elsewhere in the United Kingdom, Canada, Croatia, Iceland, Malta, Morocco, Spain, and the United States. The series premiered on HBO in the United States on April 17, 2011, and its seventh season ended on August 27, 2017. The series will conclude with its eighth season premiering either in 2018 or 2019.[1] 
 

 
Set on the fictional continents of Westeros and Essos, Game of Thrones has several plot lines and a large ensemble cast but centers on three primary story arcs. The first story arc centers on the Iron Throne of the Seven Kingdoms and follows a web of alliances and conflicts among the dynastic noble families either vying to claim the throne or fighting for independence from the throne. The second story arc focuses on the last descendant of the realm's deposed ruling dynasty, exiled and plotting a return to the throne. The third story arc centers on the longstanding brotherhood charged with defending the realm against the ancient threats of the fierce peoples and legendary creatures that lie far north, and an impending winter that threatens the realm.Game of Thrones has attracted record viewership on HBO and has a broad, active, international fan base. It has been acclaimed by critics, particularly for its acting, complex characters, story, scope, and production values, although its frequent use of nudity and violence (including sexual violence) has been criticized. The series has received 38 Primetime Emmy Awards, including Outstanding Drama Series in 2015 and 2016, more than any other primetime scripted television series. Its other awards and nominations include three Hugo Awards for Best Dramatic Presentation (2012–2014), a 2011 Peabody Award, and four nominations for the Golden Globe Award for Best Television Series – Drama (2012 and 2015–2017). Of the ensemble cast, Peter Dinklage has won two Primetime Emmy Awards for Outstanding Supporting Actor in a Drama Series (2011 and 2015) and the Golden Globe Award for Best Supporting Actor – Series, Miniseries or Television Film (2012) for his performance as Tyrion Lannister. Lena Headey, Emilia Clarke, Kit Harington, Maisie Williams, Diana Rigg, and Max von Sydow have also received Primetime Emmy Award nominations for their performances in the series. 
 
    </div> 
 
    <a href="#" class="more-less">Read More...</a> 
 
</div> 
 
<div class="card"> 
 
    <div class="content"> 
 
    Game of Thrones is an American fantasy drama television series created by David Benioff and D. B. Weiss. It is an adaptation of A Song of Ice and Fire, George R. R. Martin's series of fantasy novels, the first of which is A Game of Thrones. It is filmed in Belfast and elsewhere in the United Kingdom, Canada, Croatia, Iceland, Malta, Morocco, Spain, and the United States. The series premiered on HBO in the United States on April 17, 2011, and its seventh season ended on August 27, 2017. The series will conclude with its eighth season premiering either in 2018 or 2019.[1] 
 

 
Set on the fictional continents of Westeros and Essos, Game of Thrones has several plot lines and a large ensemble cast but centers on three primary story arcs. The first story arc centers on the Iron Throne of the Seven Kingdoms and follows a web of alliances and conflicts among the dynastic noble families either vying to claim the throne or fighting for independence from the throne. The second story arc focuses on the last descendant of the realm's deposed ruling dynasty, exiled and plotting a return to the throne. The third story arc centers on the longstanding brotherhood charged with defending the realm against the ancient threats of the fierce peoples and legendary creatures that lie far north, and an impending winter that threatens the realm.Game of Thrones has attracted record viewership on HBO and has a broad, active, international fan base. It has been acclaimed by critics, particularly for its acting, complex characters, story, scope, and production values, although its frequent use of nudity and violence (including sexual violence) has been criticized. The series has received 38 Primetime Emmy Awards, including Outstanding Drama Series in 2015 and 2016, more than any other primetime scripted television series. Its other awards and nominations include three Hugo Awards for Best Dramatic Presentation (2012–2014), a 2011 Peabody Award, and four nominations for the Golden Globe Award for Best Television Series – Drama (2012 and 2015–2017). Of the ensemble cast, Peter Dinklage has won two Primetime Emmy Awards for Outstanding Supporting Actor in a Drama Series (2011 and 2015) and the Golden Globe Award for Best Supporting Actor – Series, Miniseries or Television Film (2012) for his performance as Tyrion Lannister. Lena Headey, Emilia Clarke, Kit Harington, Maisie Williams, Diana Rigg, and Max von Sydow have also received Primetime Emmy Award nominations for their performances in the series. 
 
    </div> 
 
    <a href="#" class="more-less">Read More...</a> 
 
</div>

+0

嘿!你能否給我編輯的問題給一個答案? –

+1

@RajMalhotra回答編輯請批准回答 –

+0

你在開玩笑嗎?它不工作:) – Styx

1

你可以檢查當前文本是什麼,並做其他事情。

$(document).ready(function(){ 
    $("#click-me").on("click", function(){ 
    if ($(this).html() === "Read More") { 
     // Change to Read Less 
    } else { 
     // Change to Read More 
    } 

    }); 
}); 
0

您可以使用HTML5 data-*屬性具有相同事件的不同表決:

$("#click-me").on("click", function(){ 
    if ($(this).attr("data-shouldOpen") != "false") { 
     $(this).attr("data-shouldOpen", "false"); 
     open(); // opening code here 
    } else { 
     $(this).attr("data-shouldOpen", "true"); 
     close(); // closing code here 
    } 
}); 

可以被打開不同的div關聯通過/關門鈕釦。

2

我用一個類的委託來控制狀態。

$(document).ready(function(){ 
 
    $('#read-options') 
 
    .on('click', "#click-me.expanded", function(){ 
 
     $(this).html("Read More").removeClass('expanded'); 
 
     $(".content").css("overflow",""); 
 
     $(".content").css("height",""); 
 
    }).on('click', "#click-me:not(.expanded)", function(){ 
 
     $(this).html("Read Less").addClass('expanded'); 
 
     $(".content").css("overflow","auto"); 
 
     $(".content").css("height","auto"); 
 
    }); 
 
});
.card{ 
 
    border: 1px solid black; 
 
    margin: 10px; 
 
    padding: 20px; 
 
} 
 
.content{ 
 
    overflow: hidden; 
 
    height: 40px; 
 
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<div class="card"> 
 
    <div class="content"> 
 
    Game of Thrones is an American fantasy drama television series created by David Benioff and D. B. Weiss. It is an adaptation of A Song of Ice and Fire, George R. R. Martin's series of fantasy novels, the first of which is A Game of Thrones. It is filmed in Belfast and elsewhere in the United Kingdom, Canada, Croatia, Iceland, Malta, Morocco, Spain, and the United States. The series premiered on HBO in the United States on April 17, 2011, and its seventh season ended on August 27, 2017. The series will conclude with its eighth season premiering either in 2018 or 2019.[1] 
 

 
Set on the fictional continents of Westeros and Essos, Game of Thrones has several plot lines and a large ensemble cast but centers on three primary story arcs. The first story arc centers on the Iron Throne of the Seven Kingdoms and follows a web of alliances and conflicts among the dynastic noble families either vying to claim the throne or fighting for independence from the throne. The second story arc focuses on the last descendant of the realm's deposed ruling dynasty, exiled and plotting a return to the throne. The third story arc centers on the longstanding brotherhood charged with defending the realm against the ancient threats of the fierce peoples and legendary creatures that lie far north, and an impending winter that threatens the realm.Game of Thrones has attracted record viewership on HBO and has a broad, active, international fan base. It has been acclaimed by critics, particularly for its acting, complex characters, story, scope, and production values, although its frequent use of nudity and violence (including sexual violence) has been criticized. The series has received 38 Primetime Emmy Awards, including Outstanding Drama Series in 2015 and 2016, more than any other primetime scripted television series. Its other awards and nominations include three Hugo Awards for Best Dramatic Presentation (2012–2014), a 2011 Peabody Award, and four nominations for the Golden Globe Award for Best Television Series – Drama (2012 and 2015–2017). Of the ensemble cast, Peter Dinklage has won two Primetime Emmy Awards for Outstanding Supporting Actor in a Drama Series (2011 and 2015) and the Golden Globe Award for Best Supporting Actor – Series, Miniseries or Television Film (2012) for his performance as Tyrion Lannister. Lena Headey, Emilia Clarke, Kit Harington, Maisie Williams, Diana Rigg, and Max von Sydow have also received Primetime Emmy Award nominations for their performances in the series. 
 
    </div> 
 
    <span id="read-options"> 
 
    <button id="click-me">Read More</button> 
 
    </span> 
 
</div>

+0

精彩的使用'click'事件! –

+0

??你爲什麼使用'$(this).html(「Read Less」)'而不是'$('#click-me')'? –

+0

'this'將是click-me,因爲這是委託上的子選擇器篩選器。這是一個問題的複製粘貼,:) – Taplar

2

答案已經更新回答其他問題。

實現這個最簡單的方法是創建額外的CSS類並通過單擊切換它。看到你想讓它適用於多個按鈕,我們也應該更新HTML。該代碼將不會依靠按鈕id屬性:

$(document).ready(function(){ 
 
    $(".toggle-more").on("click", function(){ 
 
    $(this).closest(".card").toggleClass("show-more"); 
 
    }); 
 
});
.card { 
 
    border: 1px solid black; 
 
    margin: 10px; 
 
    padding: 20px; 
 
} 
 
.card .content { 
 
    overflow: hidden; 
 
    height: 40px; 
 
} 
 
.card.show-more .content { 
 
    overflow: auto; 
 
    height: auto; 
 
} 
 
.card .toggle-more:before { 
 
    content: "Read More"; 
 
} 
 
.card.show-more .toggle-more:before { 
 
    content: "Read Less"; 
 
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<div class="card"> 
 
    <div class="content"> 
 
    Game of Thrones is an American fantasy drama television series created by David Benioff and D. B. Weiss. It is an adaptation of A Song of Ice and Fire, George R. R. Martin's series of fantasy novels, the first of which is A Game of Thrones. It is filmed in Belfast and elsewhere in the United Kingdom, Canada, Croatia, Iceland, Malta, Morocco, Spain, and the United States. The series premiered on HBO in the United States on April 17, 2011, and its seventh season ended on August 27, 2017. The series will conclude with its eighth season premiering either in 2018 or 2019.[1] 
 
    Set on the fictional continents of Westeros and Essos, Game of Thrones has several plot lines and a large ensemble cast but centers on three primary story arcs. The first story arc centers on the Iron Throne of the Seven Kingdoms and follows a web of alliances and conflicts among the dynastic noble families either vying to claim the throne or fighting for independence from the throne. The second story arc focuses on the last descendant of the realm's deposed ruling dynasty, exiled and plotting a return to the throne. The third story arc centers on the longstanding brotherhood charged with defending the realm against the ancient threats of the fierce peoples and legendary creatures that lie far north, and an impending winter that threatens the realm.Game of Thrones has attracted record viewership on HBO and has a broad, active, international fan base. It has been acclaimed by critics, particularly for its acting, complex characters, story, scope, and production values, although its frequent use of nudity and violence (including sexual violence) has been criticized. The series has received 38 Primetime Emmy Awards, including Outstanding Drama Series in 2015 and 2016, more than any other primetime scripted television series. Its other awards and nominations include three Hugo Awards for Best Dramatic Presentation (2012–2014), a 2011 Peabody Award, and four nominations for the Golden Globe Award for Best Television Series – Drama (2012 and 2015–2017). Of the ensemble cast, Peter Dinklage has won two Primetime Emmy Awards for Outstanding Supporting Actor in a Drama Series (2011 and 2015) and the Golden Globe Award for Best Supporting Actor – Series, Miniseries or Television Film (2012) for his performance as Tyrion Lannister. Lena Headey, Emilia Clarke, Kit Harington, Maisie Williams, Diana Rigg, and Max von Sydow have also received Primetime Emmy Award nominations for their performances in the series. 
 
    </div> 
 
    <button class="toggle-more"></button> 
 
</div> 
 
<div class="card"> 
 
    <div class="content"> 
 
    Game of Thrones is an American fantasy drama television series created by David Benioff and D. B. Weiss. It is an adaptation of A Song of Ice and Fire, George R. R. Martin's series of fantasy novels, the first of which is A Game of Thrones. It is filmed in Belfast and elsewhere in the United Kingdom, Canada, Croatia, Iceland, Malta, Morocco, Spain, and the United States. The series premiered on HBO in the United States on April 17, 2011, and its seventh season ended on August 27, 2017. The series will conclude with its eighth season premiering either in 2018 or 2019.[1] 
 
    Set on the fictional continents of Westeros and Essos, Game of Thrones has several plot lines and a large ensemble cast but centers on three primary story arcs. The first story arc centers on the Iron Throne of the Seven Kingdoms and follows a web of alliances and conflicts among the dynastic noble families either vying to claim the throne or fighting for independence from the throne. The second story arc focuses on the last descendant of the realm's deposed ruling dynasty, exiled and plotting a return to the throne. The third story arc centers on the longstanding brotherhood charged with defending the realm against the ancient threats of the fierce peoples and legendary creatures that lie far north, and an impending winter that threatens the realm.Game of Thrones has attracted record viewership on HBO and has a broad, active, international fan base. It has been acclaimed by critics, particularly for its acting, complex characters, story, scope, and production values, although its frequent use of nudity and violence (including sexual violence) has been criticized. The series has received 38 Primetime Emmy Awards, including Outstanding Drama Series in 2015 and 2016, more than any other primetime scripted television series. Its other awards and nominations include three Hugo Awards for Best Dramatic Presentation (2012–2014), a 2011 Peabody Award, and four nominations for the Golden Globe Award for Best Television Series – Drama (2012 and 2015–2017). Of the ensemble cast, Peter Dinklage has won two Primetime Emmy Awards for Outstanding Supporting Actor in a Drama Series (2011 and 2015) and the Golden Globe Award for Best Supporting Actor – Series, Miniseries or Television Film (2012) for his performance as Tyrion Lannister. Lena Headey, Emilia Clarke, Kit Harington, Maisie Williams, Diana Rigg, and Max von Sydow have also received Primetime Emmy Award nominations for their performances in the series. 
 
    </div> 
 
    <button class="toggle-more"></button> 
 
</div>

+0

嘿!你能否給我編輯的問題給一個答案? –

+1

@RajMalhotra是的,但在未來,我強烈建議你提出一個新問題,而不是在同一問題中多問。 – Styx

+0

當然,下次會記住這一點 –

0
$(document).ready(function(){ 
    $("#click-me").on("click", function(){ 
    $(this).toggleClass('readLess'); 
    $(".content").toggleClass('hidden'); 
    if($(this).hasClass('readLess')){ 
     $(this).text("Read Less"); 
    }else{ 
     $(this).text("Read More"); 
    } 
    }); 
}); 

.hidden { 
    overflow: auto; 
    height: auto; 
} // add this to your styles