I am showing/hiding DIVs like this:
HTML:
<a href="#" class="showhide" source="one"> Show/Hide </a>
<div id="one"></div>
<a href="#" class="showhide" source="two"> Show/Hide </a>
<div id="two"></div>
jQuery:
jQuery('.showhide').live( 'click' , function () {
source = $(this).attr("source");
$( '#' + source ).slideToggle( 'slow' );
return false;
});
Now I want to ask 2 things:
-
How can I change text ‘Show/Hide’ to Show when Div is closed and Hide when DIV is open?
-
How can I hide all these DIVs when page is loaded first time?
Any improvements in above code are also appreciated.
Thanks.
You could use the
callbackfunction within theslideToggleto change the text according to the:visibleselector.As for hiding the
div, with your current markup a simplenext().hide();should solve that.example: http://jsfiddle.net/niklasvh/pdcxs/