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.
-
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
- "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml"><head>
- <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
- <title>jQuery Test</title>
-
- <script type="text/javascript" src="/js/lib/jquery-1.4.2.js"></script>
- <script type="text/javascript">
- /*<![CDATA[*/
- (function($) {
- $(document).ready(function() {
- function _escape($str) {
- //return $str.replace(/([#;&,.+*~':"!^$\[\]()=>|\/])/gi, '\\$1');
- return $str.replace(/([ #;&,.+*~\':"!^$[\]()=>|\/])/g,'\\$1')
- }
-
- $('[id="' + _escape('//root[1]/node[1]/@attr') + '"]').html('Shit happens!');
- $('[id="' + _escape('#tab-selected') + '"]').html('Selected tab');
- });
-
- })(jQuery);
- /*]]>*/
- </script>
- </head>
- <body>
- <div id="//root[1]/node[1]/@attr" >
- Nothing happens!!
- </div>
-
- <div id="#tab-selected" >
- Not selected tab
- </div>
-
- </body>
- </html>
Can somebody help me? Is it jQuery or browser specific problem?