title: How to Ignore the error in querySelector?
body: <p>I have a function on my <code>javascript</code> with <code>querySelector</code> when I clicked the <code>Logout button</code> the <code>querySelector</code> throws an error. How do I ignore this error? Because It blocks my <code>function Logout()</code>.</p>
  <p>Here's my <code>querySelector</code> function</p>
  <pre class="lang-js prettyprint-override"><code>const parent = document.querySelectorAll('.nav-link');
  
  for (var i = 0; i &lt; parent.length; i++) {
      parent[i].onclick = (e) =&gt; {
          const current_child = e.currentTarget.querySelector('.items-title').innerText;
          swal.fire({
              html: &quot;Loading..&quot;,
              timer: 1000,
              icon: &quot;info&quot;,
              timerProgressBar: true,
              allowEscapeKey: false,
              allowOutsideClick: false,
              showConfirmButton: false,
              showCancelButton: false,
              didOpen: () =&gt; {
                  timerInterval = setInterval(() =&gt; { }, 100)
              },
              willClose: () =&gt; {
                  clearInterval(timerInterval);
              }
          }).then(() =&gt; {
              $.ajax({
                  url: &quot;/Shop/Results&quot;,
                  data: {
                      result: current_child,
                  },
                  type: &quot;GET&quot;,
                  dataType: &quot;html&quot;,
                  success: function (result) {
                      $(&quot;#result&quot;).html(result);
                      $(&quot;.false&quot;).html(result);
                  }
              })
          })
      }
  }
  </code></pre>
  <p>Here's my HTML logout:</p>
  <pre class="lang-html prettyprint-override"><code>&lt;li class=&quot;nav-item&quot;&gt;
    &lt;a class=&quot;nav-link first changing-color&quot;&gt;@ViewBag.username&lt;/a&gt;
  &lt;/li&gt;
  &lt;li class=&quot;nav-item&quot;&gt;
    &lt;a class=&quot;nav-link first changing-color&quot; id=&quot;search&quot;&gt;&lt;i class=&quot;fal fa-search&quot;&gt;&lt;/i&gt;&lt;/a&gt;
    &lt;select class=&quot;form-control&quot; id=&quot;search-bar&quot; onmousedown=&quot;if(this.options.length&gt;8){this.size=8;}&quot; onchange='this.size=0;' onblur=&quot;this.size=0;&quot;&gt;
      &lt;option selected&gt;&lt;/option&gt;
    &lt;/select&gt;
  &lt;/li&gt;
  &lt;li class=&quot;nav-item&quot;&gt;
    &lt;a class=&quot;nav-link first changing-color&quot; asp-action=&quot;Index&quot; asp-controller=&quot;Wishlist&quot;&gt;&lt;i class=&quot;fal fa-heart&quot;&gt;&lt;/i&gt;&lt;/a&gt;
  &lt;/li&gt;
  &lt;li class=&quot;nav-item&quot;&gt;
    &lt;a class=&quot;nav-link first changing-color&quot; asp-action=&quot;Index&quot; asp-controller=&quot;Cart&quot;&gt;&lt;i class=&quot;fal fa-shopping-cart&quot;&gt;&lt;/i&gt;&lt;/a&gt;
  &lt;/li&gt;
  &lt;li class=&quot;nav-item&quot;&gt;
    &lt;a class=&quot;nav-link first changing-color&quot;&gt;₱@ViewBag.savings&lt;/a&gt;
  &lt;/li&gt;
  &lt;li class=&quot;nav-item&quot;&gt;
    &lt;form asp-action=&quot;Logout&quot; asp-area=&quot;&quot; asp-controller=&quot;Home&quot; method=&quot;post&quot; id=&quot;logout&quot;&gt;
      &lt;a class=&quot;nav-link first changing-color&quot; onclick=&quot;logout()&quot;&gt;LOGOUT&lt;/a&gt;
    &lt;/form&gt;
  &lt;/li&gt;
  </code></pre>
  <p>Here's my HTML to use <code>querySelector</code></p>
  <pre class="lang-html prettyprint-override"><code>&lt;div class=&quot;image-background&quot;&gt;
    &lt;div class=&quot;container&quot;&gt;
      &lt;div class=&quot;text-center&quot;&gt;
        &lt;div class=&quot;wrapper-content&quot;&gt;
          &lt;div class=&quot;wrapper-title&quot;&gt;
            SHOP
          &lt;/div&gt;
          &lt;br /&gt;
          &lt;div class=&quot;wrapper-nav&quot;&gt;
            &lt;nav class=&quot;navbar navbar-expand-lg navbar-dark bg-transparent&quot;&gt;
              &lt;div class=&quot;container&quot;&gt;
                &lt;button class=&quot;navbar-toggler&quot; style=&quot;margin: auto;&quot; type=&quot;button&quot; data-bs-toggle=&quot;collapse&quot; data-bs-target=&quot;#shopbar&quot; aria-controls=&quot;shopbar&quot; aria-expanded=&quot;false&quot; aria-label=&quot;Toggle navigation&quot;&gt;
                                  &lt;span class=&quot;navbar-toggler-icon&quot;&gt;&lt;/span&gt;
                              &lt;/button&gt;
                &lt;div class=&quot;collapse navbar-collapse&quot; id=&quot;shopbar&quot;&gt;
                  &lt;ul class=&quot;navbar-nav mx-auto mb-2 mb-lg-0&quot;&gt;
                    &lt;li class=&quot;nav-item&quot;&gt;
                      &lt;a class=&quot;nav-link&quot; id=&quot;unca&quot;&gt;
                        &lt;table&gt;
                          &lt;tr&gt;
                            &lt;th rowspan=&quot;2&quot;&gt;&lt;/th&gt;
                            &lt;th class=&quot;items-title&quot;&gt;UNCATEGORIZED&lt;/th&gt;
                          &lt;/tr&gt;
                          &lt;tr&gt;
                            &lt;td&gt;@ViewBag.total_items ITEMS&lt;/td&gt;
                          &lt;/tr&gt;
                        &lt;/table&gt;
                      &lt;/a&gt;
                    &lt;/li&gt;
                  &lt;/ul&gt;
                &lt;/div&gt;
              &lt;/div&gt;
            &lt;/nav&gt;
          &lt;/div&gt;
        &lt;/div&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  <p>I removed some of my <code>&lt;li&gt;</code></p>