In the jQuery manual itself it shows the blur function as:
.blur(handler(eventObject)) // PLUS 2 OTHER VARIATIONS
So to me using this function you would get something like this:
<!DOCTYPE html>
<html>
<head>
<script src="http://code.jquery.com/jquery-latest.js"></script>
</head>
<body>
<form>
<input id="target" type="text" value="Field 1" />
<input type="text" value="Field 2" />
</form>
<div id="other">Trigger the handler</div>
<script>
$('#target').blur(myhandler(evObj));
function myhandler(evObj) {
console.log(evObj);
};
</script>
</body>
</html>
But $('#target').blur(myhandler(evObj)); is not the correct syntax the correct syntax is really $('#target').blur(myhandler);
So overall the entire code for script tag should be:
<script>
$('#target').blur(myhandler);
function myhandler(e) {
console.log(e);
};
</script>
- Why is this so?
- How is someone supposed to know NOT to write
.blur(handler(eventObject))?