casper.start(URL, function() { casper.page.injectJs('C:/Users/Mike/Documents/n1k0-casperjs-bc0da16/jquery-1.10.2.min.js'); var names = $('span.author-name'); this.echo(names); this.exit(); }
ReferenceError: Can't find variable: $
What do I do? I've tried this too when creating the casper instance:
var casper = require('casper').create({ // I've tried both commented lines below // clientScripts: ['C:/Users/Mike/Documents/n1k0-casperjs-bc0da16/jquery-1.10.2.min.js'] // clientScripts: ['includes/jquery-1.10.2.min.js'] });
JQuery: jQuery isn't necessary, But it will be useful in chrome extension at some points like logging in the URL or etc. First, download a version of jQuery from the jQuery CDN and put it in your extension's folder, and add the name of the minified version of jquery. To load it, add it to manifest.
jQuery is a JavaScript library, so it operates on top of JavaScript. It cannot exist on its own, so you can't use one over the other. You can use just JavaScript or JavaScript and jQuery. jQuery was introduced to make development with JavaScript easier.
Yes, they're both JavaScript, you can use whichever functions are appropriate for the situation. Show activity on this post. That kind of lower-level hacking around the DOM, messing with the inline handlers, and cross-browser quirks thereof, is precisely the reason jQuery was born.
JQuery can be used to develop Ajax based applications. It can be used to make code simple, concise and reusable. It simplifies the process of traversal of HTML DOM tree. It can also handle events, perform animation and add ajax support in web applications.
You have evaluate the jQuery code in the browser context using casper.evaluate
execute code as if you were using the browser console.
var nameCount = this.evaluate(function() { var names = $('span.author-name') return names.length; }); this.echo(nameCount);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With