Count characters in paragraph using jQuery (*not* for input/textarea)

Use

$("#myDiv").text().length;

var $div = $('#mydiv');
if($div.text().length >= 50) {
    $div.addClass('class');
}

Put a "long" class on all div and p elements with more than 50 characters:

$("p, div").filter(function(){
  return $(this).text().length >=50;
}).addClass('long');

If you don't know how much content you have, though, then presumably this content is generated dynamically by the server, right? And if this is the case, wouldn't it make more sense to have the server—which knows how much content it's plopping into these containers—add the class dynamically while generating the page to send? Why rely on jQuery?