从img标签中检索值



我想获得favoriteid的值。

<td class="favoriteRow" style="">
<img src="/images/starGold.png" loading="lazy" favoriteid="bitcoin">
</td>

这是我试过的,但得到了undefined

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

console.log(此)输出:

<td class="favoriteRow" style="">
<img src="/images/starGold.png" loading="lazy" favoriteid="bitcoin">
</td>

像这样?

看医生!

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>

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>

最新更新