Custom read more read less with jquery
Custom read more and read less when content will extra: I have some content in a box when my content will be extra then show read more button and my extra content will be hidden. When clicking on the read more button then will be show content and show read less button. When clicking on the read less button then will hide extra content from my content box.
Here is an example, I think your problem will be solved now: You can copy paste this code:
HTML Code:
CSS Code:
Jquery Code:
Here is an example, I think your problem will be solved now: You can copy paste this code:
HTML Code:
<div class="anything">
<div id="anything"> Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard
dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen
book.<br> <br>
<p>vived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It
was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently
with desktop publishing software like </p><br>
<p>vived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It
was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently
with desktop publishing software like </p><br>
<div>ved not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was
popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently
with desktop publishing software l</div><br> It has survived not only five centuries, but also the leap into
electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset
sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including
versions of Lorem Ipsum. </div><span class="moreC"> Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type</span>
<div class="readMore">Read More</div>
<div class="readLess">Read Less</div>
</div>
CSS Code:
<style>
.readLess {
display: none;
}
.anything {
border: 1px solid #ddd;
background: #f5f5f5;
padding: 10px;
font: normal 14px Arial, Helvetica, sans-serif;
}
#anything p {
margin: 0;
padding: 0;
}
.readLess,
.readMore {
background: #3CF;
color: #fff;
padding: 5px 10px;
width: 80px;
margin: 10px 0px;
cursor: pointer
}
.readLess:hover,
.readMore:hover {
background: #090
}
</style>Jquery Code:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
<script>
var conte = $("#anything").text().length;
var conte1 = $("#anything").text();
var bx1 = conte1.slice('', 200);
if (conte > 200) {
$("#anything").after("<span
class='moreC'>" + bx1 + "</span>" + "<div class='readMore'>Read More</div><div
class='readLess'>Read Less</div>");
$("#anything").css("display", "none"); };
$(".readMore").click(function () {
$("#anything").slideDown("slow");
$(".moreC").css("display", "none");
$(".readLess").css("display", "block");
$(this).css("display", "none");
});
$(".readLess").click(function () {
$("#anything").slideUp("slow");
$(".moreC").css("display", "block");
$(".readMore").css("display", "block");
$(this).css("display", "none");
});
</script>
No comments:
Note: Only a member of this blog may post a comment.