are there any problems mixing my code with standard javascript and jquery? Will things conflict? Would I be unable to use standard javascript within jquery calls?
jQuery is framework for JavaScript
This means that if you use jQuery, you use JavaScript at the same time.
So no, there will be no issues if you put JavaScript inside the code that already uses jQuery, because you add nothing new / conflicting. Because you already are using JavaScript within your code.
jQuery does a good job of keeping itself compartmentalized within the jQuery (or $) object, so it plays well with existing JavaScript, and even with other JS APIs. The only thing I can think of that you should really look out for is if you use $ elsewhere (for example, if you use PrototypeJS). In that case, you can use jQuery's noConflict.
The only issues you will find is if your code overwrites the base prototypes. Otherwise your code will work fine with javascript libraries and frameworks including JQuery.
No there wont be any problems.
JQuery is just JavaScript written by other developers available to you through an API. Therefore, JavaScript inside JQuery is just JavaScript inside JavaScript.
I have had some problems with using onclick="javascript......" handlers at the same time as using jQuery handlers.
I would suggest if using jQuery to tend toward using it's handler system rather than the html versions.
Related
I was going to run jQuery and Javascript at the same time, but I want to make sure it works before I actually do it. Can Chrome run both languages at the same time?
jQuery is a library of JavaScript functions. jQuery is written 100% in JavaScript and it just gives you a set of functions that you can use to make things easier/faster to develop.
So yes, you can use them both at the same time.
jQuery is a JavaScript library, so jQuery IS JavaScript. You definitely can use both (jQuery and vanilla JS) through each other, but maybe it's not a good idea to keep your source code readable.
I'm working on a JavaScript library which needs to give the user the ability to run some code on load. Of course, I'm familiar with window.onload, and things like $(function() {}); with jQuery. But I don't want to be dependent on another library, and I want this particular function (along with the rest of the lib, of course) to be cross-browser.
So is there an accepted way of attaching to the onload function without overriding another library's load functionality (or having mine overwritten if they include another lib after mine)?
Expose an initialization/onload method and require it be called by the consumer on load. In other words, push the issue off to whomever is using the library and will likely have a convenient method like that offered by jQuery.
This is a solved problem but it isn't simple: the answer to "$(document).ready equivalent without jQuery" has the code of how jQuery does this.
More hits: javascript onload without jQuery
Background
I am new to Node.JS but very experienced with JavaScript and jQuery. I have had no problem installing jQuery via npm install jquery, however, referencing plugins within the code is another challenge.
I have reviewed this similar StackOverflow question, and the solution appears to work but it seems to me that instantiating a "fake" browser window and injecting your jQuery plugin-based functions each time you need the plugin is possibly not the most efficient approach.
The specific plugin that is failing for me linq.js (yes, I am aware that js linq is available via npm but it is not the same as linq.js!).
NOTE: The plugin to which I am referring does not rely on any DOM elements; in my case, it simply runs JSON objects through various data functions. This is why I don't think I need to instantiate a window object.
Question
How do I properly import and use jQuery plugins in a Node.JS application?
You can't do this. JQuery manipulates DOM on the client-side, which means that it has no business on the server-side where NodeJs runs.
You don't.
You don't use jQuery on the server, ever. It has no place there, you don't have a DOM on the server and jQuery itself is a mediocre library to start with.
If you really want to use a "jQuery plugin" in node, you rewrite the plugin as a standalone module without a jQuery dependency.
As an aside, you also shouldn't need linq.js because it's an API you don't need, you already have array methods. Also your coding C# in JavaScript rather then learning JavaScript.
You also have all the array methods (map, filter, reduce, etc) so you simply do not need this. If you really want some of the sugar linq.js offers use underscore instead. (I personally recommend for ES5 over underscore)
Please use ECMAScript correctly rather then emulating C#.
I am attempting to create an html document parser with Python. I am very familiar with jQuery and I would like to use its traversing functionality to parse these html files and return the data gathered with jQuery back to my Python program.
Is there any way to use javascript scripts through Python? Or is this just a pipe dream?
You might not need to do this. There is a Python module called PyQuery that directly emulates the API for jQuery. It works exactly as you would expect it to in almost every way. Give it a shot!
jQuery itself does not contain an HTML/XML parser at all. It uses the browser to do all its parsing. Thus, even if you figure out how to run Javascript from Python, it won't do you any good.
jQuery doesn't parse HTML - it traverses the DOM. You'd need an entire rendering engine (e.g. WebKit) if you wanted to use jQuery to work on the HTML.
Well from your question it seems you will require python-javascript bridge like
Pyjamas http://pyjs.org/ , PyPy http://codespeak.net/pypy/dist/pypy/doc/ , skulpt http://www.skulpt.org/ . Or my personal favorite PyXPCOM http://pyxpcomext.mozdev.org/ it installs a python backend directly into the firefox browser and using xpi stubs one can make bidirectioal calls ( mind you very complicated )
Is it possible to have 2 different jQuery versions in the same document, and have them to not collide with each other?
For example if I create a bookmarklet and want to base the code on jQuery.
This bookmarklet is injected on some page that uses another version of jQuery then my code would overwrite the version used on the page.
Is it possible to avoid that?
Or are there some other libraries that provides this functionality
Or maybe I should rethink the whole thing.
Thanks for answers and pointers,
bob
jQuery comes with a way to avoid collisions. After you load the first version, you can assign it to a different variable.
var $j = jQuery.noConflict();
And then load your second jQuery version. The first one you load can be accessed with $j(...) while the second one can be accessed with $(...).
Alternatively, somebody made a little helper in an attempt to make it easier to switch between different versions.
Here is a way to detect is JQuery is already present: jQuery in widget
Work out the oldest version of JQuery your code will work with.. And refuse to work if the version present is too old. Only a few people will miss out, most sites using JQuery are pretty up to date..
Why not just have different versions of your javascript, for different versions of jquery, so, look at what version is on the page and get the appropriate code that will work on that version of jquery.
This would be safer, as anything else may be very fragile, as it sounds like you don't have control over the version of jquery that will be on the page.