title: Getting an error "Cannot read property 'click' of undefined" if selector or class cannot be found in the DOM
body: <p>I'm getting error <code>Cannot read property 'click' of undefined</code>. I'm currently trying to automate/emulate a click function using the code below.</p>
  
  <p><code>$('.trigger-pdf')[0].click();</code></p>
  
  <p>I believe the error happens if javascript cannot find the selector in the markup/DOM or if it does not exist. Is there a way to resolve an error like this. </p>