0

Seems simple, but I can't wrap my head around it. I am trying to toggle the content and have it show after clicking on the button div. I've tried writing a javascript function to toggle close and open but can't get it. Any help is appreciated.

            <div class="et_pb_module et_pb_toggle et_pb_toggle_close  et_pb_toggle_0 et_pb_toggle_item">
            <h5 class="et_pb_toggle_title">Content Button</h5>
            <div class="et_pb_toggle_content clearfix">
                <p> Content</p>

            </div> <!-- .et_pb_toggle_content -->
        </div> <!-- .et_pb_toggle -->
1
  • Please post your JavaScript attempt, otherwise it appears as if you're asking us to do all the work for you, which this site isn't about Commented Oct 3, 2017 at 18:39

3 Answers 3

1

You can use toggle() function, like below :

$('.et_pb_toggle_title').on("click",function(){
   $('.et_pb_toggle_content').toggle();
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="et_pb_module et_pb_toggle et_pb_toggle_close  et_pb_toggle_0 et_pb_toggle_item">
  <h5 class="et_pb_toggle_title">Content Button</h5>
  <div style="display:none;" class="et_pb_toggle_content clearfix">
    <p> Content</p>
  </div>
</div>

Sign up to request clarification or add additional context in comments.

1 Comment

if you'd like to start with the content hidden add inline style="display:none;" to the div with class et_pb_toggle_content
1

So you need to have a click event, either inline (inside the tag of the element you want to click)

//Make a unhide function that sets the display to show, then call it using this
onclick="unhide();"

Or, in the JS file you can have an event listener such as follows.

document.getElementById("clickButton").addEventListener("click",function() {
    //Give the hidden element display:none; in the CSS
    document.getElementById("clickButton").style.display = inline;
}

Comments

1

Apart from using regular toggle, you can also use fadeToggle() to have it fade in and out, or slideToggle() to let it appear/disappear animated from/to the top.

$('.et_pb_toggle_title').on("click", function() {
  $('.et_pb_toggle_content').fadeToggle();
});
.et_pb_toggle_content {
  display: none;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="et_pb_module et_pb_toggle et_pb_toggle_close  et_pb_toggle_0 et_pb_toggle_item">
  <h5 class="et_pb_toggle_title">Content Button</h5>
  <div class="et_pb_toggle_content clearfix">
    <p> Content</p>
  </div>
</div>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.