• Skip to primary navigation
  • Skip to main content

Genesis Community

Resources for Genesis WordPress Theme Users

  • Facebook
  • Twitter
  • Slack
  • Wiki
  • Login
You are here: Home / Wikis / JS / Toggle an element when a button is clicked

Toggle an element when a button is clicked

const seeMore = document.getElementById("seeMoreBtn");
const article = document.getElementById("article");

seeMore.addEventListener("click", () => {
    article.classList.toggle("expanded");

    const expanded = article.classList.contains("expanded");
    if (expanded) {
        seeMore.innerHTML = "See Less";
    } else {
        seeMore.innerHTML = "See More";
    }
});
Source: https://dev.to/sarah_chima/using-css-transitions-on-the-height-property-al0

Posted by: Sridhar Katakam Category: JS

« Smooth Scrolling
Resetting select menu value in all other select menus »

Copyright © 2026 · Genesis Sample on Genesis Framework · WordPress · Log in