Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jquery length of text()

Tags:

html

jquery

What's 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 I.E 6 saying function expected on the line marked error.

like image 808
van Avatar asked Jul 19 '10 16:07

van


2 Answers

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

like image 174
sushil bharwani Avatar answered Oct 05 '22 02:10

sushil bharwani


Many things are wrong:

  1. You didn't include jQuery in your page and you try to use functions from it
  2. You didn't close your script tag
  3. Your div is completely broken
  4. You don't have a DOCTYPE
  5. Your document doesn't have a head :-)
  6. Your script is outside of the html
  7. length is a property not a function
like image 26
Darin Dimitrov Avatar answered Oct 05 '22 03:10

Darin Dimitrov