I am currently injecting an iframe and binding a keyevent both to the document and the iframe.
Can I select both the iFrame and the document in one row?
notice the iframe must have .contents() after the selector
// wait for iframe to load
$('iframe#iframe').load(function() {
// event bind to document
$(document).bind('keydown', function(e) {
console.log("runs document");
});
// event bind to iframe
$(this).contents().bind('keydown', function(e) {
console.log("runs iframe");
});
});
You can use
.add(), like this:This takes the iframe contents then just adds the
documenton the returned jQuery object as well, resulting in both being having the handler to theirkeydownevent.