jQuery Selecting elements by dynamic name with square brackets (fiddle incl)
<p>How can I make this fiddle work:
<a href="http://jsfiddle.net/gAHwW/" rel="nofollow">http://jsfiddle.net/gAHwW/</a></p>

<pre><code>function $escape(string) { 
    return string.replace(/\\(\[|\]\\)/g,'\\\\$1');
}

$(function() {
    $('input[type="button"]').click(function() {
        alert($escape( $(this).attr('id') )); // to show you what the escape does

        $('#' + $(this).attr('id')).hide(); // doesn't work
        $('#' + $escape( $(this).attr('id') )).hide(); // doesn't work
        $('#alsosquare[]').hide(); // doesn't work

        //$(this).hide(); // works
        //$('#alsosquare\\[\\]').hide(); // works
    });
});​
</code></pre>

<p>I need to select elements by their name/id dynamically, and their names/ids can have square brackets.</p>

<p>Thanks!</p>
