Is there an easy way to convert jquery code to javascript?

davidsleeps picture davidsleeps · Jun 11, 2009 · Viewed 136.4k times · Source

Is there an easy way to convert jQuery code to regular javascript? I guess without having to access or understand the jQuery source code.

Answer

Indolering picture Indolering · Dec 6, 2013

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.