View Single Post
Old 09-23-2009, 09:20 PM   #1 (permalink)
EyeDentify
The Acquainted
 
EyeDentify's Avatar
 
Join Date: Nov 2007
Location: Sweden
Posts: 106
Thanks: 13
EyeDentify is on a distinguished road
Default 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);
 }
		
});
__________________
Of course the whole point of a doomsday machine, would have been lost if you keep it a secret.
EyeDentify is offline  
Reply With Quote