JQuery text length ()

What is wrong with the below

<html>
<body>
<div id='test')28</div>
</body>
</html>

<script>
$(document).ready(function (){
  if ($('#test').text().length() > 0) // error here?
   alert("test");
});

I get a javascript error in IE 6 talking about a function expected in a line with an error mark.?

+5
source share
6 answers

Length in javascript is not a function. its so property uses length () instead of length ()

+15
source

Many errors are incorrect:

  • You have not included jQuery on your page and are trying to use functions from it
  • You have not closed the tag script
  • Your div is completely broken.
  • You do not have DOCTYPE
  • Your document is not head:-)
  • Your script is outside of html
  • length - property, not function
+13
source

length . .

'lol'.length === 3 // true
+5

JQuery . javascript.length.

, Javascript JQuery. ( )

0

next to length(), there is another mistake

<div id='test')28</div>
0
source

You are looking for this function. .lengthBut before use, .lengthyou need to add a text value.

Answer: $("#test").val().length

0
source

All Articles