3

I can't get Netbeans to auto-complete my selectors for JQuery, example:

<a id="hello" href="#">Hello</a>
<script type="text/javascript">
    $("|").hide();
</script>

As far as i understand the documentation at this point it should show the tags available on the page when i press control+space at the | position, but instead displays no suggestions. Links [1] and [2] shows clearly that this has been implemented. I have not tried prototype, link [2] shows that JQuery support has been added as well.

The auto-complete of functions works perfectly, with the embedded library of JQuery 1.4.2, it is only the selector auto-complete that does not work. Any suggestions?

[1] http://wiki.netbeans.org/JavaScript#Embedded_Completion

[2] http://wiki.netbeans.org/JavaScript#Recently_Added

Product Version: NetBeans IDE 6.8 (Build 200912041610)
Java: 1.6.0_18; Java HotSpot(TM) Client VM 16.0-b13
System: Windows XP version 5.1 running on x86; Cp1252; en_US (nb)

5 years later update:

As of at least version 8.0.2 Netbeans now properly auto-completes jQuery selectors in both php and html pages. I am unsure if this is due to some other changes on the editor engine or they finally caught the discrepancy but either way it works now, yay!

2 Answers 2

2

Naor answer made me rethink what I was doing, but it didn't quite answer my question. So let me provide the solution I found in case anyone is interested.

When working with netbeans, the auto-complete function behaves differently between php files and html. In html jquery selectors auto-completes as expected. But when trying to do the same within a php file in an html section of code, it will fail to auto-complete.

Just make sure that if you are expecting this feature to work, that you are using html files, not php. I will submit this as a feature/bug to the netbeans guys, hopefully they can fix it and make html/js auto-completion available to all file types that can include html/js code.

3
  • If you wouldn't mind adding a link to that bug report or sending it to me via an IM, I'd love to put my weight behind it via an upvote since this is something that has bothered me for quite some time.
    – 133794m3r
    Jun 25, 2011 at 6:23
  • Any movement on this ?
    – MarcoZen
    Apr 30, 2015 at 12:31
  • I never reported this to the netbeans team, but I can confirm that in netbeans 8.0.2 it works as expected in both php and html files :D
    – Katsuke
    May 24, 2015 at 2:17
2

Link 1 says that there is code completion on element ids that appear in the html itself. They also say that it works with Prototype.js. I believe that it would work for jquery too, but don't forget - in order to select an element using it id in jquery you do $('#id') - with #.

What they meant in their example if you have $("f|") is that if you start writing $("f and the cursor of typing is after the f (they put "|" in order to mark the cursor), then code completion should show all relevant elements.

Try that:
in html: <div id="blabla">12345</div>
in jscript: $('bl');
after the bl press control+space, and I believe that it will display to you blabla.

1
  • Sorry for the delay, but the answer is a bit different. The suggested documentation works as expected with JQUERY selectors (say .class or #id) The reason behind why it didn't work was because i was working in a .php file. As soon as i created a file with .html it worked perfectly. I guess the problem is that html suggestions in php files is different from html files in netbeans. Thanks for your suggestion though, it lead me to question my assumptions :)
    – Katsuke
    Jun 5, 2011 at 4:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.