Interactive Toggle for Full and Half Details Sections with Slick Button Integration

PHOTO EMBED

Fri Mar 01 2024 21:37:08 GMT+0000 (Coordinated Universal Time)

Saved by @Y@sir #social-share-icons #share-icons #social-share-buttons

document.addEventListener("DOMContentLoaded", function () {
  const toggleButton = document.getElementById("fulltoggleButton");
  const myDiv = document.getElementById("fulldetailssection");
  const halfdetailssection = document.getElementById("halfdetailssection");

  if (toggleButton) {
    toggleButton.addEventListener("click", function () {
      toggleSections();
    });
  }

  const halftoggleButton = document.getElementById("halftoggleButton");

  if (halftoggleButton) {
    halftoggleButton.addEventListener("click", function () {
      toggleSections();
    });
  }

  // Attach click event to the document body for specific slick buttons
  document.body.addEventListener("click", function (event) {
    const target = event.target;
    const isSlickButton = target.matches(".wpl-el-property-slider-section .slick-next, .wpl-el-property-slider-section .slick-prev, .wpl-el-testimonial-section .slick-next, .wpl-el-testimonial-section .slick-prev");

    if (isSlickButton) {
      if (myDiv.style.display !== "none") {
        myDiv.style.display = "none";
        halfdetailssection.style.display = "block";
      }
    }
  });

  function toggleSections() {
    if (myDiv.style.display === "none") {
      myDiv.style.display = "block";
      halfdetailssection.style.display = "none";
    } else {
      myDiv.style.display = "none";
      halfdetailssection.style.display = "block";
    }
  }
});
content_copyCOPY

The provided JavaScript code manages the visibility toggling of two sections in response to button clicks. The script targets specific buttons, such as those within slick sliders, to control the display of two div sections: "fulldetailssection" and "halfdetailssection." Clicking on the designated buttons alternately hides and displays these sections, ensuring that the "halfdetailssection" is visible when the "fulldetailssection" is hidden. Additionally, the script supports toggling these sections by clicking on separate buttons labeled "fulltoggleButton" and "halftoggleButton." The overall goal is to create an interactive UI where certain button clicks control the visibility state of specific content sections.