Reputation: 1
<div id="sidebar_archive_infoline_bottom"><a id="showallnews" href="#">SHOW ALL NEWS</a></div>
<script>
$('#newsdiv').hide();
$('#showallnews').click(function () {
$('#newsdiv').slideToggle('fast');
$('#showallnews').text('CLOSE')
}); </script>
The text "SHOW ALL NEWS" changes to "CLOSE" after clicking the first time on it. Now I need a method to change it from "CLOSE" to "SHOW ALL NEWS" and so on...
Best regards!
Upvotes: 0
Views: 728
Reputation: 5933
<script>
$('#newsdiv').hide();
$('#showallnews').click(function() {
$('#newsdiv').slideToggle('fast', function() {
$('#showallnews').text().toLowerCase().indexOf('close') != -1 ? $('#showallnews').text('SHOW ALL NEWS') : $('#showallnews').text('CLOSE');
});
});
</script>
Upvotes: 2
Reputation: 396
Try this
<script>
...
$("#showallnews").toggle(function (){
$("#showallnews").text("SHOW ALL NEWS")
.stop();
}, function(){
$("#showallnews").text("CLOSE")
.stop();
});
</script>
Upvotes: 0
Reputation: 528
$('#showallnews').click(function () {
$('#newsdiv').slideToggle('fast');
$('#showallnews').addClass("closed");
$('#showallnews').text('CLOSE')
});
$('.closed').click(function(){
$('#newsdiv').slideToggle('fast');
$('#showallnews').removeClass("closed");
$('#showallnews').text('Show all news')
})
Not the best way but this can do.
Upvotes: 0