"object doesn't support property or method" inside generic autocomplete function
<p>When setting up an autocomplete the following line works fine:</p>

<pre><code>$("[id$='_txtUserName']").autocomplete({  ... etc
</code></pre>

<p>But I want to refactor a bit and create a generic function into which I can pass any text box as an object and there is more than one textbox I need to set up similarly. Unfortunately the following code does not work</p>

<pre><code>function SetupAutocomplete(ctrl) {
    ctrl.autocomplete({  ... etc
</code></pre>

<p>... as when calling it in either of these ways:</p>

<pre><code>SetupAutocomplete($("[id$='_txtUserName']").get(0));
</code></pre>

<p>or</p>

<pre><code>SetupAutocomplete($("[id$='_txtUserName']")[0])
</code></pre>

<p>..neither work and it throws the <code>object does not support the property or method 'autocompete'</code> error. I really don't want to have to write the same thing <em>x</em> number of times for each text box I need to setup.</p>

<p>Any ideas on why it doesn't like the <code>ctrl.autocomplete</code> line? I'm guessing because it doesn't know it's a text input type but why not and what can I do about it?</p>

<p>Server side is c# but doubt that's at all relevant as it works fine when setting up the autocomplete explicitly.</p>