User Tools

Site Tools


Eclipse: jQuery code completion

There are two ways of having the code completion in Eclipse.

The global way

This method involves adding the jQuery library to the project. You can do the same for every library you want (e.g. motools).

  • Download jQuery.js files and put it somewhere outside of your project (just to have it only once for all projects)
  • Go to Preferences → Web → JavaScript → Include Path → User Libraries.
  • Click 'New' and name it 'jQuery' or whatever you like.
  • Select this new 'jQuery' item and click 'Add .js file'.
  • Select jQuery.js file.
  • Click 'OK' and close the preferences.
  • Open your project and in 'Javascript Resources' make sure you have jQuery (or the name you've chosen above)

You'll soon discover that's not so good because it doesn't work with $. or $().

The tailored better way

  • Help→Install new software
  • You'll see the JSDT jQuery plugin. Check and install it.
  • Now open the project you want to feature the jQuery code completion.
  • Go in properties→javascript→Include path→Libraries→Add jajascript library.
  • You'll see a new entry: 'jQuery library'. Select and click Finish.
  • Now you can finally type $. and $() and you'll see the code completion

NB: If you don't see 'Javscript' in the property of the project, that's only because the project was not initially created with javascript support option.
You can verify this point taking a look a the last items of the project (under you files): you probably won't see 'Javascript resources' icon.
In this case you only have to add the javascript support:

  • In PHP Explorer view, right-click your project.
  • Select Configure→Add Javascript Support OR (depending on the Eclipse version) Configure→Convert to Javascript project is the only option (apart from starting a new project from scratch with javascript enabled).
ide/eclipse-jquery-code-completion.txt · Last modified: 2020/06/04 18:48 by rik