Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

246
Views
Can't display text on my site with my .js file

I can't find why I can't write some .innerHTML to add some text on my site.

Here is a part of my HTML :

<table>
  <tr>
    <td class="test1"></td>
    <td class="test2"></td>
    <td class="test3"></td>
    <td class="test4"></td>
  </tr>
</table>

...

  </main>
  <script src="./test.js"></script>
</body>
<footer>

Here is a part of my JS :

const $test1 = document.querySelector('.test1')
$test1.innerHTML = `test`;

In this example, I want to display "text" in the first case of the first line of my table. But nothing is displayed. Maybe these 2 files are not well linked? Idk...

Hope I you have enough information, do not hesitate to ask me for more details!!!

Thanks a LOT in advance.

Have a nice day.

Here is to confirm the path is correct? enter image description here

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

You need to wrap your html code with the <table> tag. <td> and <tr> elements have to reside within a element. You can read more about this issue here

Another issue you have is that the <td> elements are closed by the </th> tags.

 var test1 = document.querySelector(".test1");
 test1.innerHTML = 'test';
<table>
  <tr>
    <td class="test1"></td>
    <td class="test2"></td>
    <td class="test3"></td>
    <td class="test4"></td>
  </tr>
</table>

about 4 years ago · Juan Pablo Isaza Report

0

You can check this small snippet here:

document.querySelector('table td.test1').innerHTML = `test`
<table>
  <tr>
    <td class="test1"></td>
    <td class="test2"></td>
    <td class="test3"></td>
    <td class="test4"></td>
</tr>
</table>

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!