what if you want to add or remove some css using the same button? Jquery comes with a handy toggle() function.
Toggle function needs at least two arguments. All arguments will be functions.
when you click on the toggle selector the functions will be triggered. One function will be triggered at a time. On the next click the next function will be triggered let's look at the following example.
Javascript code:
$('#post5').toggle(function(){
$('#post5 div').animate({'width':'400px'},'slow').text('click to squeeze!');
},
function(){
$('#post5 div').animate({'width':'200px'},'slow').text('click to make large!');
}
);
You can see I have used only two functions. You can use more. Enjoy toggling!
No comments:
Post a Comment