having to double click using .click and .text
Hello,
I have the script below to toggle open and close identified divs on a page. On page load I have to click twice on the link for it to work (from there on, one click suffice). Can someone help me with what is wrong with it?
Thanks
script
- <script type="text/javascript">
- $(document).ready(function(){
- $("#toggle_all").toggle(function(){
- $(".toggle_container_wide").slideUp(80);
- $("h5.trigger").addClass("active");}, function () {
- $("h5.trigger").removeClass("active");
- $(".toggle_container_wide").slideDown(80);
- }); });
- $('#toggle_all').click(function() {
- $(this).text($(this).text() == ' Open All' ? '- Close All' : ' Open All');
- return false;
- });
- </script>
html
- <a id="toggle_all" href="#">Open All</a>