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

131
Views
How to acces the src to a td element that has id?

Table

I have a table, and each cell has it's a unique ID, how to access the src value and change it?

<tr><td id="ROOM11"><img src="01.png"></td><td id="ROOM12"

This JavaScript code try to access the src but it returns with null value:

let cellid = document.querySelector("#ROOM11");
console.log(cellid.getAttribute('id'));//I manage to access the ID: returns  ROOM11
cellid.setAttribute('src',02.png'); //returns with an error
cellid.getAttribute('src'); //returns with null

I maybe need to access the child element but I don't know how to access it?

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

0

Change your selector to #ROOM11 img. #ROOM11 by itself will only select the element with the id ROOM11.

let cellid = document.querySelector("#ROOM11 img");
console.log(cellid)

cellid.setAttribute('src', 'https://www.gravatar.com/avatar/0fdacb141bca7fa57c392b5f03872176?s=48&d=identicon&r=PG&f=1');
<table>
  <tr>
    <td id="ROOM11"><img src="01.png"></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!