Checking if element exists with jQuery -


i have block of code looks this:

//account number         account = $(msg).find('[name=account_number]').val();          if(account){             $('#progressupdates').append('<span class="glyphicon glyphicon-ok"></span>&nbsp;&nbsp;found account number<br />');         }else{             $( '#progressupdates').append('<span class="glyphicon glyphicon-remove"></span>&nbsp;&nbsp;account number not found<br />');         } 

the problem is, if element being assigned account doesn't exist, throws error. tried doing :

if(account.length){} 

but issue isn't if statement, assigning variable. there better solution this?

don't call val()

account = $(msg).find('[name=account_number]');

and chack length -

if(account.length){


Comments

Popular posts from this blog

php - regexp cyrillic filename not matches -

c# - OpenXML hanging while writing elements -

sql - Select Query has unexpected multiple records (MS Access) -