-1

I want to get the favoriteid value.

<td class="favoriteRow" style="">

  <img src="/images/starGold.png" loading="lazy" favoriteid="bitcoin">

</td>

This is what I tried but got back undefined.

console.log(this.childNodes[0]['favoriteid'])

The console.log(this) outputs:

<td class="favoriteRow" style="">

  <img src="/images/starGold.png" loading="lazy" favoriteid="bitcoin">

</td>
Reginald1234
  • 335
  • 3
  • 13
  • It’s very strange that you figured to log `this` and `this.childNodes[0].favoriteid` but never logged `this.childNodes` or `this.childNodes[0]` to see what they are. – Sebastian Simon Sep 20 '21 at 13:47

1 Answers1

1

Something like this?

See docs!

const img = document.querySelector("img[favoriteid]");
console.log( img.getAttribute("favoriteid") )
<td class="favoriteRow" style="">
  <img src="/images/starGold.png" loading="lazy" favoriteid="bitcoin">
</td>

or

document.querySelector(".favoriteRow img").getAttribute("favoriteid")

console.log(document.querySelector(".favoriteRow img").getAttribute("favoriteid"));
<table>
  <td class="favoriteRow" style="">
    <img src="/images/starGold.png" loading="lazy" favoriteid="bitcoin">
  </td>
</table>
stacj
  • 1,103
  • 1
  • 7
  • 20