I want to trigger the same function from 2 different events.  Is the
following the best way to do this?  Note in this code snippet, the 2
separate events are page load/button click.

<button id="button">Click me</button>

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/
libs/jquery/1.2.6/jquery.min.js"></script>
<script type="text/javascript">
function myHandler() {
    alert('hello');
}

$(document).bind('LOAD', function() {
        myHandler();
});

$(document).trigger('LOAD');
$('#button').bind('click', myHandler);
</script>

Reply via email to