Я работал над сценарием содержимого для расширения Chrome, и ElementID продолжает показывать ноль, несмотря на то, что консоль показывает, что ElementID был найден. Есть идеи, что я делаю не так?
if (document.readyState !== 'loading') {
myInitCode();
} else {
document.addEventListener('DOMContentLoaded', function() {
myInitCode();
});
}
function myInitCode() {
var idSection = document.getElementById("price");
console.log("ID SECTION", idSection); //test to see if ID was found
var button = document.createElement('button');
var text = document.createTextNode("Click Me");
button.appendChild(text);
idSection.appendChild(button);
// idSection.attachShadow({ mode: 'open' }); //create shadow root
//idSection.appendChild(button); //Append to Shadow Root
}
Консоль:
![](https://i.stack.imgur.com/04VlR.png)