Escaping special chars in ID selector does not work in IE with version bellow 8

Escaping special chars in ID selector does not work in IE with version bellow 8

I write some interface that maps XML to HTML DIV elements with XPath in its ID. I know restrictions of ID element but in other browser its works finely (other than < IE8).
The simple test fails in IE6, IE7. This test passes in IE8, FF, Opera and Google Chrome.
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  2.         "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  3. <html xmlns="http://www.w3.org/1999/xhtml"><head>
  4.     <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
  5.     <title>jQuery Test</title>


  6.     <script type="text/javascript" src="/js/lib/jquery-1.4.2.js"></script>
  7.     <script type="text/javascript">
  8.     /*<![CDATA[*/
  9.     (function($) {
  10.         $(document).ready(function() {
  11.             function _escape($str) {
  12.                //return $str.replace(/([#;&,.+*~':"!^$\[\]()=>|\/])/gi, '\\$1');
  13.                return $str.replace(/([ #;&,.+*~\':"!^$[\]()=>|\/])/g,'\\$1')
  14.             }


  15.             $('[id="' + _escape('//root[1]/node[1]/@attr') + '"]').html('Shit happens!');
  16.             $('[id="' + _escape('#tab-selected') + '"]').html('Selected tab');
  17.         });


  18.     })(jQuery);
  19.     /*]]>*/
  20.     </script>
  21. </head>
  22. <body>
  23. <div id="//root[1]/node[1]/@attr" >
  24.     Nothing happens!!
  25. </div>


  26. <div id="#tab-selected" >
  27.     Not selected tab
  28. </div>


  29. </body>
  30. </html>
Can somebody help me? Is it jQuery or browser specific problem?