tags:

views:

62

answers:

4

Hi,

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..?

+3  A: 

length is not a function. it is a property.

'lol'.length === 3 // true
meder
+5  A: 

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

sushil bharwani
+10  A: 

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
Darin Dimitrov
thanks point 7 the rest was quick mock up to show the scenario.
nav
A: 

Don't use JQuery to get length. Just use the standard javascript .length command.

There are a few functions that Javascript can handle without JQuery's help. (hyperbole intended)

Ben Guthrie