I am trying to constantly check for any update on the page. I want to influence the second object on the page by checking if the user clicks a button that makes first object display as a block
So user click button > first object displays block > the second object should move. how do I constantly check for any changes in Javascript?
I currently have this
const button = document.querySelector(".btn")
const firstObject = document.querySelector(".first-object")
btn.addEventListener("click", function(){
if(firstObject.style.display === "none"){
firstObject.style.display = "block"
} else {
firstObject.style.display = "none"
}
})
So this sets the ".first-object" div to block or hides it , Now I want my second div to get a margin-top of 50px when the ".first-object" is set to block and so I added this
const secondObject= document.querySelector(".second-object")
if (object.style.display = "block"){
secondObject.style.marginTop = "50px";
} else {
secondObject.style.marginTop = "0";
}
But this part doesnt constantly check if the other value returns true. How do I achieve this?
Sorry for my noobish question and thanks in advance!
Aucun commentaire:
Enregistrer un commentaire