17

I know all internal jQuery functions are written in JavaScript, so it should technically be possible to just evaluate jQuery to JavaScript.

I have a snippet of JavaScript that uses jQuery that I need to use in an environment where jQuery isn't available. I know I could translate it by hand, but it is quite a lot of code. Is there a tool out that that does this?

Just to make it clear: with a lot of effort I could probably get jQuery in the environment but I would like to have a solution that is a bit more resource friendly. If there is no tool like this I'll just try to translate the code by hand, I was just wondering whether there was such a tool.

8
  • 3
    jQuery is JavaScript. There is no border to cross here. I would think it is impossible to extract "just the necessary parts" from it, you should focus on getting jQuery into your environment, if you need it. Commented Jan 25, 2012 at 22:09
  • 2
    I know jQuery is built up from JavaScript. I'm not saying I would like to extract some parts of jQuery. Say I have $(".classname"). This would be roughly equivalent to document.getElementsByClassName("classname"). I was just asking if there is a tool that does this kind of stuff programmatically. Commented Jan 25, 2012 at 22:31
  • No, there isn't. Everything in jQuery depends on everything in jQuery. While there might be easy substitutes for easy cases, even with your simple example there is a problem: not every browser supports getElementsByClassName(), but every browser jQuery runs on supports $(".classname"). Commented Jan 25, 2012 at 22:38
  • 1
    Okay, I was just wondering if there was a tool that helped with replacing jQuery statements with the actual underlying code. I take it there is no such tool. Commented Jan 25, 2012 at 22:46
  • 3
    This is a reasonable question. I was also looking for a transcompiler hoping to map jQuery to native inline JavaScript for various reasons. Commented Mar 17, 2014 at 11:53

1 Answer 1

16

Google's Closure Compiler's advanced optimization compresses your code to only include parts that are necessary, so the parts of jQuery that aren't used are stripped away.

Sign up to request clarification or add additional context in comments.

1 Comment

Is it necessary to copy and paste the whole JQuery code in that website?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.