TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   Javascript, AJAX, E4X (http://www.talkphp.com/javascript-ajax-e4x/)
-   -   Accessing Lenght of a string in Javascript with jQuery (http://www.talkphp.com/javascript-ajax-e4x/4963-accessing-lenght-string-javascript-jquery.html)

EyeDentify 09-23-2009 09:20 PM

Accessing Lenght of a string in Javascript with jQuery
 
I have been learning some jQuery and things are shaping up pretty well. But i have hit my head on the following thing.

In this bit of code that works fine there is a part where i am trying to get the lenght of the 'altVar' variable but nothing seem to happen.

The only thing i can think of is that 'altVar' is no longer a object and donīt have a lenght property ?

am i thinking in the wrong direction here or is the late hours making my brain a little fuzzy.

I turning to you JavaScript gurus here on the site.
Have a look at this code. It all works well except that i want the code in the IF statement only to be TRUE if the lenght of the string taken from the alt attribute of the targeted element is more then 0.

The return from 'var strLen = altVar.lenght' is 'undefined' ?
i donīt get it. Why ?

I should mention im a newbie in the JavaScript realm :)

If you need any other info to help me out, just tell me what you need :)

Thanks in advance.

Code:

$("a.menuLink").mouseenter(function() {
 // Animate
 $(this).animate({paddingLeft:"+20px"}, { duration: 400 });

 // Get data out of elements alt attribute.
 // also find out string lenght
       
 var altVar = $(this).attr('alt');
 var strLen = altVar.lenght;
 
 // show status div only if string
 // is more then 0 in lenght
 if(strLen > 0)
 {
  $('#statusDiv').show();
  $('#statusDiv').html(altVar);
 }
               
});


Salathe 09-23-2009 09:24 PM

There is no lenght property, the correct English word (and indeed the correct property name) would be length

EyeDentify 09-23-2009 09:28 PM

Quote:

Originally Posted by Salathe (Post 28492)
There is no lenght property, the correct English word (and indeed the correct property name) would be length

Ow.... do i feel stupid :)

Ofcourse that would be the problem :)

And the late hours here in sweden :)

Thx, Salathe your a godsend :)

EyeDentify 09-23-2009 09:41 PM

Edit: Now the code works perfectly the way i want :)

Note to self :) property is 'length' not 'lenght'

Salathe 09-23-2009 10:00 PM

Quote:

Originally Posted by EyeDentify (Post 28493)
Thx, Salathe your a godsend :)

We all make super-simple mistakes from time to time and often it takes someone else to spot them. :-)


All times are GMT. The time now is 06:34 PM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0