#4394 closed bug (invalid)
Jquery 1.3.2 (Sizzle) cannot use attribute selectors with an odd number of apostrophes in the values.
Reported by: | Owned by: | john | |
---|---|---|---|
Priority: | major | Milestone: | 1.4 |
Component: | selector | Version: | 1.3.2 |
Keywords: | quotes | Cc: | [email protected]… |
Blocked by: | Blocking: |
Description
Given some elements with apostrophe's in their attribute values:
$("body").append("<span title='James's'>Here</span>"); $("body").append("<span title='St. James's Places'>There</span>");
I expect $("[title=\"James's\"]").text() to be "Here" and $("[title=\"St. James's Place\"]).text() to be "There".
In the first case what I get (with various attempts at escaping the apostrophe) is:
$("[title=\"James's\"]").text() | Syntax error, unrecognized expression: title="James's"] |
$("[title=\"James's\"]").text(); | "" |
$("[title=James's]").text(); | Syntax error, unrecognized expression: title=James's] |
$("[title=James\'s]").text(); | Syntax error, unrecognized expression: title=James's] |
$("[title=James 's]").text(); | Syntax error, unrecognized expression: title=James\'s] |
Trying for the second one, I get slightly different exceptions:
$("[title=\"St. James's Place\"]").text(); | Syntax error, unrecognized expression: Place"] |
$("[title=\"St. James's Place\"]").text(); | "" |
$("[title=St. James's Place]").text(); | Syntax error, unrecognized expression: Place] |
$("[title=St. James\'s Place]").text(); | Syntax error, unrecognized expression: Place] |
$("[title=St. James 's Place]").text(); | Syntax error, unrecognized expression: Place] |
If, however, I use an even number of apostrophes, then all is well:
$("body").append("<span title='St. James's' Place'>Yonder</span>");
$("[title=St. James's' Place]").text(); | "Yonder" |
$("[title=\"St. James's' Place\"]").text(); | "Yonder" |
$("[title=St. James\'s\' Place]").text(); | "Yonder" |
$("[title='St. James\'s\' Place']").text(); | "Yonder" |
Even $("[title='St. James's' Place']").text() results in "Yonder", which I find surprising.
Change History (3)
comment:1 Changed 14 years ago by
Component: | unfilled → selector |
---|---|
Keywords: | quotes added |
Owner: | set to john |
comment:2 Changed 12 years ago by
Resolution: | → invalid |
---|---|
Status: | new → closed |
comment:3 Changed 12 years ago by
ALSO... There is a typo here as well:
$("[title=\"St. James's Place\"]).text()
The best part is that the value of the second span'a title attr is "St. James's Places"... but you actually test for "St. James's Place" - you're missing an "s".
Please be more careful in the future
http://jsfiddle.net/rwaldron/uZhFj/1/