My favorite way is to use attributes (data). Kind of like:
<button data-paused="false"></button>
Here's a solution:
$('#btn_pause_resume').click(function () { if ($(this).data('paused')==='false') { alert('Resumed...'); $(this).data('paused', 'true'); } else { alert('Paused...'); $(this).data('paused', 'false'); } });
Quick Plugin
Here's a plugin I just wrote that will make this easy:
$.fn.toggleClick=function(t,a,e){$(this).data("ToggleState",e||false),this.click(function(){"false"===$(this).data("ToggleState")?(t(),$(this).data("ToggleState","true")):(a(),$(this).data("ToggleState","false"))})};
Add this to the top of your code and you can do:
$('#btn_pause_resume').toggleClick( function () { alert('Resumed!'); }, function () { alert('Paused!'); }, true);//True makes second function run first
This adds a toggleClick function. This function takes two functions which each run.
pausefirst, you need to swap your code in theif/else. Is this in a$(document).ready(function(){or$(function(){?