When working with JavaScript, remember that =
is used as an assignment operator, while ==
is used for comparison operations.
In order to modify your block of code, follow these instructions:
setTimeout(function () {
var e = document.getElementById("keep-ads"),
t = document.getElementsByClassName("adsbygoogle")[0]; // assuming there's only one element with this class name
if(t.style.display == "none") { // make the necessary change here
e.className += "up";
}
}, 2e3);
UPDATE:
If you want to add a class to an id when a class is hidden using JavaScript
Utilize element.style.display = 'none';
to hide an element and check the style.display
property of the element.
function hidekeep() {
document.getElementById("keep-ads").style.display = "none"
}
setTimeout(function () {
var e = document.getElementById("keep-ads"),
t = document.getElementsByClassName("adsbygoogle")[0]; // assuming there's just one element with the given class name
if(t.style.display == 'none') { // modification made here
e.className += "up";
}
}, 2e3);
var hideBar1 = function() {
document.getElementsByClassName("adsbygoogle")[0].style.display = 'none';
};
document.getElementsByClassName("hide-ads")[0].addEventListener('click', hideBar1 , false);
.up {color:red;}
<div id="keep-ads">Foo1
</div>
<div class="adsbygoogle">Bar1
</div>
<button class="hide-ads">
HIDE
</button>