I'm using jQuery with jsdom in my node.js app.
Moreover, I want to use jQuery plugins(e.g. jQuery.diff), but I cannot find how to do this. Is ther开发者_开发问答e any way out?
Create a script tag in your document to load your script into it. Example:
createWindow = function(fn) {
var window = jsdom.jsdom().createWindow(),
script = window.document.createElement('script');
jsdom.jQueryify(window, function() {
script.src = 'file://' + __dirname + '/some.library.js';
script.onload = function() {
if (this.readyState === 'complete') {
fn(window);
}
}
});
}
createWindow(function(window) {
// Do your jQuery stuff:
window.$('body').hide();
});
Source: http://blog.davidpadbury.com/2010/10/03/using-nodejs-to-render-js-charts-on-server/
I have a library that I'm working on which is a port of jquery to node - bit.ly/node-jquery
The goal is to do var $ = require('node-jquery')
and use jquery libraries or functions as normal
精彩评论