简体   繁体   中英

Trying to change the display style using Javascript through a click event listener

This code of mine is not working.

document.getElementById("information-read-more").addEventListener("click", function(){
    document.getElementsByClassName("read-more-less-inner").style.display= "block";
});

Trying to build a read more section of my HTML that hides on mobile and reappears when the user clicks a button.

The style sheet has a media query that sets the display to none on a div with the read-more-less-inner class when the window gets small enough. Im wanting this read more button to override the style I made and show it.

The event listener fires when I click it, just the style doesnt change.

I dont think it makes a difference but im doing the project in a wordpress page.

Amys comment was the solution. Thanks!

Changed it from a class to an ID and it works now.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM