Malformed selector fails when using $el.find(..), but not when using $(..)
I came upon what I think is a bug when trying to refactor some code to use a common parent element. When splitting the selector up into a common part and using .find for the specific part it suddenly failed with a Syntax error since the attribute selector is missing the closing bracket. Using just the specific part as the selector in the main jQuery function works though, as does using a compound selector. Is there a difference in how selectors are parsed in the $(..) function and in the find(..) function, and should there be?
Of course I should just update the selector to be properly formed, but I am curious as to why the two functions differ.
- <div class='a'>
- <div>
- <a href='#1'></a>
- </div>
- </div>
- <div class='a'>
- <div>
- <a href='#2'></a>
- </div>
- </div>
- <div class='a'>
- <div>
- <a href='#3'></a>
- </div>
- </div>
- $('.a [href="#1"').text('Found!'); // This works
- $('[href="#2"').text('Found!'); // This works too
- $('.a').find('[href="#3"').text('Found!'); // This fails
Demo here:
http://jsbin.com/codiyiz/edit?html,js,output