title: RefernceError: Can't find variable: deleteChap
body: <p>I am using Jquery to append elements to an element and I have added an onclick to one of the <code>&lt;td&gt;</code> to call a function present in the same file.</p>
  <p>Here is the code for the element:</p>
  <pre><code>let x = 0;
  let element = `
  &lt;td class=&quot;px-4 py-3 text-sm&quot;&gt;
    &lt;button onclick=&quot;deleteChap(${x})&quot;&gt;
       &lt;svg xmlns=&quot;http://www.w3.org/2000/svg&quot; width=&quot;16&quot; height=&quot;16&quot; fill=&quot;currentColor&quot; class=&quot;text-red-600 w-6 h-6&quot; viewBox=&quot;0 0 16 16&quot;&gt;
          &lt;path d=&quot;M2.5 1a1 1 0 0 0-1 1v1a1 1 0 0 0 1 1H3v9a2 2 0 0 0 2 2h6a2 2 0 0 0 2-2V4h.5a1 1 0 0 0 1-1V2a1 1 0 0 0-1-1H10a1 1 0 0 0-1-1H7a1 1 0 0 0-1 1H2.5zm3 4a.5.5 0 0 1 .5.5v7a.5.5 0 0 1-1 0v-7a.5.5 0 0 1 .5-.5zM8 5a.5.5 0 0 1 .5.5v7a.5.5 0 0 1-1 0v-7A.5.5 0 0 1 8 5zm3 .5v7a.5.5 0 0 1-1 0v-7a.5.5 0 0 1 1 0z&quot; /&gt;
       &lt;/svg&gt;
    &lt;/button&gt;
  &lt;/td&gt;`
  
  $('#holder').append(element)
  </code></pre>
  <p>This is the function</p>
  <pre><code>function deleteChap(x) {
  
    let chapid = chapids[x];
  
    Swal.fire({
      title: `Are you sure you want to delete the chapter? This action is irreversible.`,
      showCancelButton: true,
      confirmButtonText: 'Yes, delete it!',
    }).then((result) =&gt; {
      if (result.isConfirmed) {
        supabase.from('chapters').eq('id', chapid).delete().then(({data, error}) =&gt; {
  
          if (error) {
            erroralert(error.message);
          } else {
            successalert(`Chapter ${chapternum} - ${title} deleted successfully.`);
            window.location = `/dashboard/series/${seriesid}`;
          }
  
        })
      }
    })
  
  }
  </code></pre>
  <p>I get the following error when I click on one of the buttons: <code>ReferenceError: Can't find variable: deleteChap</code></p>
  <p>The js file is connected to the html file with <code>&lt;script defer src=&quot;/js/dnovelinfo.js&quot; type=&quot;module&quot;&gt;&lt;/script&gt;</code></p>
  <p>Can I get some help?</p>