I am building a chrome extension, and I want to add a button to every element in the DOM that belongs to a certain class. However, my code is executing before the DOM completely loads. How do I fix this? Below is my code:
$(document).ready(function() {
// var div = document.getElementsByClassName("collection-list__page"); //[0];
var divImg = document.getElementsByClassName("product-tile__badges");
var button = CreateButton();
for (i = 0; i < divImg.length; i++) {
console.log(divImg);
console.log(divImg[i].appendChild(button));
}
button.addEventListener('mouseenter', e => {
button.childNodes[1].style.display = "block"; // Makes the dropdown appear
});
button.addEventListener('mouseleave', e => {
button.childNodes[1].style.display = "none"; // Makes the dropdown disappear
});
});
Here is my manifest:
{
"name": "Withizze",
"version": "1.0",
"manifest_version": 2,
"content_scripts": [
{
"matches": ["https://www.fashionnova.com/collections/*"],
"js": ["jquery-3.5.1.min.js", "content.js"],
"all_frames": true,
"run_at": "document_end"
}
],
"web_accessible_resources": ["dropDownButton.html"]
}