javascript - Jquery .text().length counting element's code as well as characters? -


i want detect amount of characters in div , if there less five:

var n = $("#mydiv").text().length; if (n < 5){       //do   } 

but 'n' seems counting code used div self:

<div id="mydiv">  </div> 

so if there no characters within div: n = 23.

does know way adjust count characters within div itself?

trim text exclude leading , trailing spaces in text

var n = $.trim($("#mydiv").text()).length; //use string.trim() if want support ie9+ 

demo: fiddle


Comments

Popular posts from this blog

PHPMotion implementation - URL based videos (Hosted on separate location) -

javascript - Using Windows Media Player as video fallback for video tag -

c# - Unity IoC Lifetime per HttpRequest for UserStore -