Skip to main content
JavascriptSnippets

OnClick Button Display / Hide Div

By March 31, 2020April 11th, 2020No Comments

This snippet is used in Salient when a nectar button style needs an OnClick function for displaying / hiding div. Just remember to include the ID for the div you want to control.

<style>
#divID{display:none;}
</style>
<a onclick="display_div()" class="nectar-button large regular accent-color  regular-button" id="read-disclaimer" style="visibility: visible;" href="#" data-color-override="false" data-hover-color-override="false" data-hover-text-color-override="#fff"><span>Submit a Listing (I have read the disclaimer above)</span></a>
<script>
function display_div() {
  var x = document.getElementById("divID");
  if (x.style.display === "block") {
    x.style.display = "none";
  } else {
    x.style.display = "block";
  }
}
</script>

Contact us to learn more about Adopt the Web for your business

Author Jarod Thornton

More posts by Jarod Thornton