[Answered ]-HTML if div content is long show button

1👍

You need to use innerText, please change your JS code to

<script>

var content=document.getElementById("content-blog").innerText.length;

max_length = 1000 //characters
if(content > max_length){
//Do something
}
</script>

0👍

To get all the blogs and do something to them all:

let blogs = Array.prototype.slice.call(document.getElementsByClassName("article-content"));

blogs.forEach(blog => 
    if (blog.innerText.length > 1000) {

// Do stuff with the blog

    } else {}
)

You could also modify the context in your view, or add a model property to your blog mode, to make a preview_text for the blog post. Like post.content[:100] for first 100 characters of post.

Leave a comment