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.
Related
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#.
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.
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 )
I'm trying to accomplish the following:
Upload a file to the application by submitting a form (enctype: multipart/form-data) to a JSP action which handles the rest (including writing the file to the disk, processing and returning some xml data about the upload).
Until recently, I was using this plugin:
http://valums.com/ajax-upload/
This does not work well for two reasons:
it breaks on Internet Explorer
the code is written in half jquery, half native javascript and not in your usual plugin authoring form, which makes it harder to debug.
I've also looked at Uploadify ( http://www.uploadify.com/ ) but it takes a radically different approach which would require a lot of back-end changes.
Do you know any similar submit-form-in-hidden-iframe plugins that are cleaner / cross-browser compatible? Or alternative solutions that I'm missing?
Please note that I can't use a regular because of the specific requirements.
Thanks.
You can try:
https://github.com/blueimp/jQuery-File-Upload
Pretty nice & simple
It's not jQuery but this is quite nice.
http://digitarald.de/project/fancyupload/
Also YUI has an uploader.
I've had success with this one:
http://malsup.com/jquery/form/
Allthough this is not a JQuery plugin, I can recommand SwfUpload for this kind of functionality. It's a combination of Flash and javascript which allowed me to do exactly what I wanted to without having to worry about the "upload"-part.
Try jqUploader : it's written in pure jquery plugin style and uses a flash file to display a progress bar. Very easy to implement.
You may try: plupload. It's back-end independent, and cross-browser.