<div id="foo">test</div> <script> $(function(){ $("#foo").toggle(function(){alert("A");},function(){alert("B");}); $("#foo").click(); }); </script>