我正在制作Chrome扩展程序来修改页面上的HTML。这就是我所拥有的:
的manifest.json
{
"manifest_version": 2,
"name": "Trello YouTube video embed",
"version": "1.0",
"description": "Embeds YouTube video players in Trello card descriptions based on links in the card description",
"content_scripts": [{
"js": ["embed.js"],
"matches": ["https://trello.com/*"],
"run_at": "document_end"
}]
}
embed.js
var cardDesc = document.getElementsByClassName('current markeddown hide-on-edit js-card-desc js-show-with-desc');
console.log(cardDesc);
console.log('cardDesc === undefined : ' + (cardDesc === undefined).toString());
console.log('cardDesc[0] === undefined : ' + (cardDesc[0] === undefined).toString());
console.log('cardDesc.length : ' + cardDesc.length);
这是控制台的屏幕截图:https://i.imgur.com/w8UbmBg.png
问题是cardDesc
返回0
的长度,但我可以在HTMLCollection
中清楚地看到一个项目。有什么建议我可以采用不同的方式来操纵cardDesc
中的项目吗?
答案 0 :(得分:0)
尝试使用
document.querySelectorAll('.current.markeddown.hide-on-edit.js-card-desc.js-show-with-desc')
document.getElementsByClassName