Any ideas to keep 'read more' next to text and remove 'p' from var content = $(".myClass p").html(); without losing hyperlink ? Thanks a lot..
var show_char = 280;
var ellipses = "... ";
var content = $(".myClass").html();
if (content.length > show_char) {
var a = content.substr(0, show_char);
var b = content.substr(show_char - content.length);
var html = a + "<span class=\'abc\'>" + ellipses + "</span><span class=\'abc\' style=\'display:none\'>" + b + "</span><a class=\'read-more\' href=\'#\'>Read more</a>";
$(".myClass").html(html);
}
$(".read-more").click(function(e) {
e.preventDefault();
$(".read-more").text() == "Read more" ? $(".read-more").text(" Read less") : $(".read-more").text("Read more");
$(".myClass .abc").toggle();
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="myClass">
<p><a href="https://stackoverflow.com/">stackoverflow</a> is a question and answer site for professional and enthusiast programmers. It features questions and answers on a wide range of topics in computer programming. It was created to be a more open alternative to earlier question and answer sites such as Experts-Exchange.</p>
</div>