greatwanderer greatwanderer - 16 days ago 6
jQuery Question

How do I set the character limit for .load

I'm pulling in a body of text from another page, but want to limit the amount of characters the .load event pulls. How do I control the amount of characters that are pulled from the class ".paragraph"?

Here is what I have so far:

$("document").ready(function(){
// Blog Descriptions
$( ".blog-description-3" ).load( "/blog.html .blog-post:nth-of-type(3) .blog-content .paragraph");
});

Answer

You can't limit the number of characters the method pulls in. But you can manipulate the returned string and cut it to your needs with substr()

$(".blog-description-3").load("/blog.html .blog-post:nth-of-type(3) .blog-content .paragraph", function() {
    var txt = $(".blog-description-3").text().substr(0, 20);
    $(".blog-description-3").text(txt);
});
Comments