Convert Jquery to pure Javascript(vanilla JS) with few steps. First you have to load Jquery and click on convert button then it will display javascript code in below textbox. This tool will have some errors about some Jquery code and not all Jquery code are covered.
Don't get me wrong - jQuery is still a wonderful library and most often than not you will be better off using it. However, for smaller things like simple pages with limited JS interactions, browser extensions and mobile sites, you can use vanilla JS.
jQuery is a JavaScript library that helps to simplify and standardize interactions between JavaScript code and HTML elements.
A progressive JavaScript framework, Vue. js is considered a good alternative to jQuery. It is an open-source, MVVM, front-end JS framework that is considered ideal to create user interfaces and single-page apps. It is also considered good for web interfaces, desktop, and mobile app development.
This will get you 90% of the way there ; )
window.$ = document.querySelectorAll.bind(document)
For Ajax, the Fetch API is now supported on the current version of every major browser. For $.ready()
, DOMContentLoaded
has near universal support. You Might Not Need jQuery gives equivalent native methods for other common jQuery functions.
Zepto offers similar functionality but weighs in at 10K zipped. There are custom Ajax builds for jQuery and Zepto as well as some micro frameworks, but jQuery/Zepto have solid support and 10KB is only ~1 second on a 56K modem.
The easiest way is to just learn how to do DOM traversing and manipulation with the plain DOM api (you would probably call this: normal JavaScript).
This can however be a pain for some things. (which is why libraries were invented in the first place).
Googling for "javascript DOM traversing/manipulation" should present you with plenty of helpful (and some less helpful) resources.
The articles on this website are pretty good: http://www.htmlgoodies.com/primers/jsp/
And as Nosredna points out in the comments: be sure to test in all browsers, because now jQuery won't be handling the inconsistencies for you.
I just found this quite impressive tutorial about jquery to javascript conversion from Jeffrey Way on Jan 19th 2012 *Copyright © 2014 Envato*
:
http://net.tutsplus.com/tutorials/javascript-ajax/from-jquery-to-javascript-a-reference/
Whether we like it or not, more and more developers are being introduced to the world of JavaScript through jQuery first. In many ways, these newcomers are the lucky ones. They have access to a plethora of new JavaScript APIs, which make the process of DOM traversal (something that many folks depend on jQuery for) considerably easier. Unfortunately, they don’t know about these APIs!
In this article, we’ll take a variety of common jQuery tasks, and convert them to both modern and legacy JavaScript.
I proposed it in a comment to OP, and after his suggestion, i publish it has an answer for everyone to refer to.
Also, Jeffrey Way mentioned about his inspiration witch seems to be a good primer for understanding : http://sharedfil.es/js-48hIfQE4XK.html
Has a teaser, this document comparison of jQuery to javascript :
$(document).ready(function() {
// code…
});
document.addEventListener("DOMContentLoaded", function() {
// code…
});
$("a").click(function() {
// code…
})
[].forEach.call(document.querySelectorAll("a"), function(el) {
el.addEventListener("click", function() {
// code…
});
});
You should take a look.
Is there an easy way to convert jQuery code to regular javascript?
No, especially if:
understanding the examples of javascript solutions written in jQuery [is] hard.
JQuery and all the frameworks tend to make understanding the code easier. If that's difficult to understand, then vanilla javascript will be torture :)
I can see a reason, unrelated to the original post, to automatically compile jQuery code into standard JavaScript:
16k -- or whatever the gzipped, minified jQuery library is -- might be too much for your website that is intended for a mobile browser. The w3c is recommending that all HTTP requests for mobile websites should be a maximum of 20k.
w3c specs for mobile
So I enjoy coding in my nice, terse, chained jQuery. But now I need to optimize for mobile. Should I really go back and do the difficult, tedious work of rewriting all the helper functions I used in the jQuery library? Or is there some kind of convenient app that will help me recompile?
That would be very sweet. Sadly, I don't think such a thing exists.
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