Reputation: 107
I am creating a chat popup button. I want to open and close popup/div with a single button.
<div class="menu-chat">
<a href="javascript:void(0);" class="float" id="menu-open">
<img src="<?php echo plugin_dir_url( __FILE__ ) . 'buttons/chat.svg'; ?>">
</a>
<div id="menu-popup">
<ul>
<li><a href="mailto:[email protected]" id="menu-email">
<img src="<?php echo plugin_dir_url( __FILE__ ) . 'buttons/email.svg'; ?>">
</a></li>
<li><a href="tel:+923038518000" id="menu-call">
<img src="<?php echo plugin_dir_url( __FILE__ ) . 'buttons/call.svg'; ?>">
</a></li>
<li><a href="https://m.me/Printed.Mobile.Covers" id="menu-facebook">
<img src="<?php echo plugin_dir_url( __FILE__ ) . 'buttons/facebook.svg'; ?>">
</a></li>
<li><a href="https://wa.me/9203038518000" id="menu-whatsapp">
<img src="<?php echo plugin_dir_url( __FILE__ ) . 'buttons/whatsapp.svg'; ?>">
</a></li>
</ul>
</div>
</div>
I want the popup to appear when the button is clicked. When the button is clicked again I want it to disappear.
Upvotes: 2
Views: 502
Reputation: 380
The easiest way to do this is by using JQuery toggle()
method. When used with no parameters, the toggle()
method simply toggles the visibility of elements:
$(function() {
$("#menu-open").on("click", function() {
$("#menu-popup").toggle();
});
});
Upvotes: 4