Created
October 23, 2017 08:21
-
-
Save Canx/9d5a14bf080564c6920b9a97f6944632 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
const jsdom = require("jsdom-global")(); | |
const $ = require("jquery"); | |
// modify HTML | |
document.body.innerHTML = "<!DOCTYPE html><form id=\"form1\"><textarea id=\"tb1\">Hello world</textarea></form>"; | |
function keyPressed(e) { | |
console.log("keypressed"); | |
} | |
function simulateKeyEvent(htmlTag, keycode) { | |
let event = $.Event("keypress"); | |
event.which = keycode; | |
element = document.getElementById(htmlTag); | |
$(element).trigger(event); | |
} | |
// JQUERY:associate callback to jquery | |
element = document.getElementById("form1"); | |
$(element).on("keypress", keyPressed); | |
// trigger an "a" event | |
simulateKeyEvent("form1", 65); | |
simulateKeyEvent("tb1", 65); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment