I use the following code to call some stuff after clicking by an element on a page
var http = require('http');
var fs = require('fs');
var jsdom = require('jsdom');
http.createServer(function(req, res) {
res.writeHead(200, {'Content-Type': 'text/html; charset=utf8'});
var document = new jsdom.JSDOM('<!doctype html><html><head></head><body><p>Text</p></body></html>').window.document;
document.getElementsByTagName('p')[0].addEventListener('click', function() {
alert('OK');
});
var page = '<!doctype html><html>'+document.getElementsByTagName('html')[0].innerHTML+'</html>';
res.end(page);
}).listen(80, 'localhost');
But if I click the paragraph, nothing happens
I read the answer by the link https://stackoverflow.com/a/36804251/10587062 but I didn't understand how to resolve my problem