Итак, у меня есть кнопка в моем HTML, и когда я нажимаю эту кнопку, я хочу удалить некоторые элементы со страницы.
В настоящее время у меня есть функция, подобная этой, которая устанавливает слушателя для этого Кнопка.
function addListener_close(elem,i){
console.log("IN BUTTON");
elem.addEventListener("click", function(){
console.log("clicked");
//this returns 'block' which is the current display
console.log(document.getElementById("newsentry-author").style.display);
//set the display to none
document.getElementById("newsentry-author").style.display = "none";
//this returns 'none' which is the new value
console.log(document.getElementById("newsentry-author").style.display);
});}
Однако на моей странице HTML стиль элементов не изменился после нажатия кнопки.
Где я ошибся?
ОБНОВЛЕНИЕ HTML КОД
<div class="newsentry-clicked">
<img class= "newsimage" src="https://dynaimage.cdn.cnn.com/cnn/digital-images/org/044409cb-e6f2-4c5b-8eaf-26078a4edef2.jpg">
<div class="newsentry-text">
<div class="newsentry-title">Commuting in the time of coronavirus in the nation's largest subway system</div>
<div class="newsentry-author"><span style="font-weight: bold">Author: </span>Lebron James</div>
<div class="newsentry-source"><span style="font-weight: bold">Source: </span>google.com</div>
<div class="newsentry-date"><span style="font-weight: bold">Date: </span>2020/03/02</div>
<div class="newsentry-desc-clicked">Crowded trains each weekday carry more than 5 million people hardened by terror threats and track-dwelling rats, daylight assaults and diluvial water main breaks. COVID-19 is their latest worry. The spread of the virus has unleashed anxiety across the nation'…</div>
<a href="www.google.com">See Original Post</a>
</div>
<div class="close-button">×</div>
Функция связана с кнопкой .close с помощью javascript addEventListener