Cannot read property 'insertAdjacentHTML' of null

206 Views Asked by At

When I try rendering a new job to the DOM, the above error is displayed. The template literals select data from the getJob() function in my Job.js file. The id selection works when I click on a specific job from a query search. The below elements won't display in the DOM when I do that same click though. Why is my selected element null?

JS code:

    export const renderJob = job => {
  const markup = `

  <figure class="job__fig">
    <h1 class="job_role">${job.title}</h1> 
    <h1 class="company_name">${job.company}</h1>
      <h3 class="job_location">${job.location}</h3>
      <img src="${job.logo}" alt="${job.title}" class="job_img">
        <p class="job_description">${job.description}</p>
        <p class="job_URL">${job.redirectURL}</p>
        <p class="job_createdAt">${job.createdAt}</p>
  </figure> 
  
  `;
  elements.job.insertAdjacentHTML('afterbegin', markup);
};

HTML markup:

<div class="job">
    <!--
   <figure class="job__fig">
    <h1 class="job_role">Frontend Engineer</h1> 
    <h1 class="company_name">Amazon</h1>
      <h3 class="job_location">Remote</h3>
      <img src="${job.logo}" alt="${job.title}" class="job_img">
        <p class="job_description">Amazon is looking...</p>
        <p class="job_URL">https://www.linkedin.com/jobs/view/frontend-engineer-studios-applications-at-amazon-1987071787/?utm_campaign=google_jobs_apply&utm_source=google_jobs_apply&utm_medium=organic</p>
        <p class="job_createdAt">09/26/2020</p>
  </figure> 
-->                   
      
</div>
0

There are 0 best solutions below