greatwanderer greatwanderer - 1 year ago 66
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:

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

Answer Source

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);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download