Reputation: 105
I have a some content which I want show/hide using jquery. Till now using below code:
$(document).on("click",".class", function(){
$(this).next().slideToggle("fast");
});
<div class="class" Title="Click to view/hide all" id="flip">View ▼</div>
<div class="class" id="panel"><table>
Hello!!
</table>
</div>
I have many such view div
created and are working inside for loop.
My show/hide content is working fine, but I want to change text(on button) as 'show' and 'hide' whenver user clicks.
Please help.
Upvotes: 4
Views: 358
Reputation: 148180
You can use ternary conditional operator to switch between texts.
$(document).on("click",".class", function(){
$(this).next().slideToggle("fast");
$(this).text($(this).text() == 'view' ? 'hide all' : 'view');
});
Upvotes: 3