Created
December 11, 2010 19:57
-
-
Save oslego/737611 to your computer and use it in GitHub Desktop.
Custom jQuery events triggered on non-DOM elements that bubble (propagate) up to the 'document'
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE HTML> | |
<html> | |
<head> | |
</head> | |
<body> | |
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script> | |
<script type="text/javascript"> | |
(function($){ | |
//non-DOM object events that propagate up to the 'document' | |
$(document).bind('customEventName', function(e, payload){ | |
console.log(payload.content); | |
}) | |
// non-DOM object | |
var obj = {}; | |
obj.ownerDocument = document; //magic happens here | |
$(obj).trigger("customEventName", {content: "Witchcraft"}) | |
})(jQuery) | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Tried this. Does not work. I have to use $(document) for trigger instead...
http://jsfiddle.net/f8vw6ebk/
Anyway, bubble does not happen. Have to use some other approach...