title: jquery escape square brackets to select element
body: <p>Consider a input element</p>
  
  <pre><code>&lt;input id="meta[152][value]" type="text" /&gt;
  </code></pre>
  
  <p>Here the input field is <strong>dynamically</strong> generated. I need to select that field. So I used,</p>
  
  <pre><code>alert($('#meta[152][value]').val());
  </code></pre>
  
  <p>But this seems to be invalid. After searching I found, that the "square brackets" need to be escaped like <code>#meta\\[152\\]\\[value\\]</code></p>
  
  <p>So how to do that ?
  I currently use this code,</p>
  
  <pre><code>var id = "#meta[152][value]" // (I get this value by another method) I need the escaping to be done here. So that i can use as
  </code></pre>
  
  <p>/** I need the value of id to be escaped using regex,replace or any other method
      to get #meta\[152\]\[value\] 
      and not manually **/</p>
  
  <pre><code>alert($(id).val());
  </code></pre>
  
  <p>Your suggestions will be helpful !</p>