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.
- [Answered ]-Ugettext not providing correct values in a view ("caching" the old language value)
- [Answered ]-Am I reading this documentation wrong for this Django app?
- [Answered ]-Celery tasks are not adding object to db Django/Postgres
Source:stackexchange.com