I’m trying to make a dropdown suggestion box using jQuery. I have a function that looks like this:
function onChoiceSelected(index){
var item = $("#suggestionBox li").get(index);
alert("inner html: "+item.html());
currentSuggestionInput.val(item.html());
hideSuggestions();
}
For some reason, that get function is stopping execution. If I replace it with .first(), for example, it all works fine.
What am I doing wrong?
Follow up question:
- Is there some way to see what errors are happening, rather than just having silent failure?
- I’m running firebug, but I never see any errors or anything like that. Anyone know a good article about getting a proper development environment set up for this stuff?
The
getmethod returns the DOM node at the index specified. Since you are then trying to call a jQuery method on that, it will fail.The
eqmethod should do what you want. It will have the same effect as yourgetcall, but it will return a jQuery object rather than the DOM node itself.