How to inhib special chars of a string to use it as a jQuery selector?
<p>Consider the following example :</p>

<pre><code>&lt;input type="text" id="#ab&gt;cd.ef" value="foo" /&gt;

&lt;script type="text/javascript"&gt;
  var id = '#ab&gt;cd.ef';
  alert($('#' + id).length);
&lt;/script&gt;
</code></pre>

<p>This results in a syntax error, so I am looking for something to inhib the special chars of a selector.</p>

<p>Of course, for this single example, I can do :</p>

<pre><code>alert($('input').length);
</code></pre>

<p>But I will use this principle to use dynamic selectors like :</p>

<pre><code>return $('input[name="' + $(elem).attr('name') + '"]:checked').val();
</code></pre>

<p>Even if my "name" attribute contains special chars.</p>

<p>So here is my question : How to inhib special chars of a string to use it as a jQuery selector ?</p>
