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

c# - Unity IoC Lifetime per HttpRequest for UserStore -

Change the color of an oval at click in Java AWT -

I am trying to solve the error message 'incompatible ranks 0 and 1 in assignment' in a fortran 95 program. -