Reputation: 23
My basic requirement is to add a dropdown in my site. I need when someone clicks on a text, a form will show there with a animate effect from top to bottom and will again hide if we click on the text again.
You can visit my page where I want this feature:
http://test.techkalph.com/listing-plain-heading/?filter=all&type=travel-travel-agents&submit=
Here on the right sidebar, on the very top, you can see a button saying Search by Location. When you inspect that button, you can see there is a form under a div below that button which I have made display:none to hide that.
I want to show that form when click on the button and again hide that upon clicking there (Toggle feature) with some animate effect will be fine.
I have added this script there for that purpose which you can also find in the inspect element:
<script>
jQuery(document).ready(function($){
$(".section-sidebar #custom_location").click(function(){
$(".section-sidebar div #directory-advance-search-form").show();
});
$(".section-sidebar #custom_location").click(function(){
$(".section-sidebar div #directory-advance-search-form").hide();
});
});
</script>
But it is not working. Am I doing something wrong? Please visit my above page and help me to show the form on click and hide again on click.
Thank you in advance.
Upvotes: 1
Views: 55
Reputation: 23
I have added this script instead to make the form toggle with a time interval:
<script>
jQuery(document).ready(function($){
$(".section-sidebar #custom_location").click(function(){
$(".section-sidebar div #directory-advance-search-form").toggle(1000);
});
});
</script>
Users can adjust the 1000 as per their requirement here.
Thank you again Kevin.
Upvotes: 0
Reputation: 604
Your js looks to be redundant: In the same click handler, you're showing and hiding the div - effectively, you're doing nothing :)
Instead, use a single call to $(".section-sidebar div #directory-advance-search-form").toggle()
Something along the lines of:
jQuery(document).ready(function($){
$(".section-sidebar #custom_location").click(function(){
$(".section-sidebar div #directory-advance-search-form").toggle();
});
});
I tested this in the console and it works fine.
If you must use separate handlers for whatever reason (I know: sometimes projects have very odd requirements), you should use a flag-test operation:
var advIsShown=false
.show()
or .hide()
Upvotes: 1