Jquery length of attribute undefined

qba picture qba · Dec 7, 2010 · Viewed 11.9k times · Source

How can I check the length of the string that is in the attribute?This shows 'undefined' value:

var action = $(obj).closest("form").attr('action');
alert(action.length);

Answer

Nick Craver picture Nick Craver · Dec 7, 2010

Your spelling is just a bit off, .lenght should be .length:

var action = $(obj).closest("form").attr('action');
alert(action.length);