1

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>
Dylan Cole
  • 51
  • 3
  • What is `elements`? And obviously, its `job` property is null. – derpirscher Sep 28 '20 at 19:52
  • Elements is a query selector object that I created. It holds several selected DOM elements. One of those elements is the 'job' div. – Dylan Cole Sep 28 '20 at 20:20
  • What I meant was: Show how `elements` is created and how `elements.job` is set ... Because obviously `elements.job` is null. But as long as you don't show where and how it is set, nobody can help you. – derpirscher Sep 29 '20 at 08:39

0 Answers0