I have about 25 visible / hidden elements () on the page, for example ...
HTML:
<h2><a href="#" class="link1">Headline One</a></h2> <div class="toggle-item-link1">content</div> <h2><a href="#" class="link2">Headline Two</a></h2> <div class="toggle-item-link2">content</div>
JS:
$('[class^=toggle-item]').hide(); //toggle content on click $('[class^=link]').click(function() { var $this = $(this); var x = $this.attr("className"); $('.toggle-item-' + x).toggle(); $(this).text($(this).text() == 'open' ? 'close' : 'open');
So, what happens is that the text H2 (Headline One, Headline Two) is completely replaced by the text "open / close" depending on the switching state. What I want to do is add Open / Close text to the actual header depending on the switching state.
For instance:
Open Header Single / Close Header
Open Header Two / Close Header 2
I just donβt see how to do it. Any help would be great. Thank you
Mel source share