I'm trying to figure out how to pass arguments to an anonymous function in JavaScript.
Check out this sample code and I think you will see what I mean:
<input type="button" value="Click me" id="myButton" />
<script type="text/javascript">
var myButton = document.getElementById("myButton");
var myMessage = "it's working";
myButton.onclick = function(myMessage) { alert(myMessage); };
</script>
When clicking the button the message "it's working" should appear... but the myMessage
-variable inside the anonymous function is null.
This problem becomes much more evident when using jQuery since it uses a lot of anonymous functions.
How can I do this?