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

html - Sizing a high-res image (~8MB) to display entirely in a small div (circular, diameter 100px) -

java - IntelliJ - No such instance method -

identifier - Is it possible for an html5 document to have two ids? -