Selector problem: $('#\\<foo') and $('#bar\\>') works, but $('#\\<buz\\>') doesn't.
I found a problem with the following code:
- <!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Strict//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'>
- <html xmlns='http://www.w3.org/1999/xhtml' xml:lang='en'>
- <head>
- <meta http-equiv='Content-Type' content='text/html;charset=UTF-8' />
- <script type='text/javascript' src='http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.js'></script>
- <title>Selector Escaping</title>
- <script type='text/javascript'>
- //<![CDATA[
- $(function(){
- $('#foo\\>').css('background', '#99ff99');
- $('#\\<bar').css('background', '#99ff99');
- $('#\\<buz\\>').css('background', '#99ff99');
- $('#\\[qux\\]').css('background', '#99ff99');
- });
- //]]>
- </script>
- </head>
- <body>
- <div id='foo>'>#foo></div>
- <div id='<bar'>#<bar</div>
- <div id='<buz>'>#<buz></div>
- <div id='[qux]'>#[qux]</div>
- </body>
- </html>
According with official API reference, I escaped '<' and '>' characters in jQuery selector block.
As expected "#foo>" and "#<bar" are selected, but "#<buz>" isn't.
(I tested "#[buz]" for reference and it worked successfully.)
Where is wrong?