I try to find the length of a string with jquery but it doesn't work...
Here a JsFiddle : http://jsfiddle.net/3LtjdkLw/1/
HTML code:
<div id="signup-pwd">ABC</div>
Javascript code:
alert($('#signup-pwd').val().length)
Thank you!
I try to find the length of a string with jquery but it doesn't work...
Here a JsFiddle : http://jsfiddle.net/3LtjdkLw/1/
HTML code:
<div id="signup-pwd">ABC</div>
Javascript code:
alert($('#signup-pwd').val().length)
Thank you!
Because a
<div>
, unlike<input>
,<select>
and<textarea>
elements, has atextContent
/innerText
property rather thanvalue
, so you should usetext()
instead ofval()
:Updated JS Fiddle demo.
References:
text()
.val()
.