Ticket #3443 (closed bug: fixed)
Can't Select Attribute Values Containing Closing Square Bracket ]
| Reported by: | nickretallack | Owned by: | |
|---|---|---|---|
| Priority: | major | Milestone: | 1.3 |
| Component: | docs | Version: | 1.2.6 |
| Keywords: | Cc: | ||
| Blocking: | Blocked by: |
Description
Try it yourself. Add this element to a page: <input type="text" name="foo[bar]" />
Then try to select it by name: $('[name=foo[bar]]')
You get nothing, even if you try to escape it:
$('[name=foo\[bar\]]');
$('[name=foo
[bar
]]')
Playing around a little more shows that it's just the closing square brackets that break it, since $("[name*=foo[bar]") works.
Clearly it's parsing the first ] it sees as the end of the attribute selector. Any chance you guys can beef up the parser to handle this special case?
Change History
comment:1 Changed 5 years ago by flesler
- Status changed from new to closed
- Resolution set to invalid
comment:2 Changed 5 years ago by posaune02
- Status changed from closed to reopened
- Resolution invalid deleted
I have read the FAQ regarding this issue, and still I am experiencing this same defect. Granted, the following are both invalid and will not function as intended: $('[name=foo[bar]]'); and $('[name=foo\[bar\]]');
However, according to the FAQ, the following should work: $('[name=foo
[bar
]]');
It does not function as described in the FAQ.
comment:3 Changed 5 years ago by flesler
- Status changed from reopened to closed
- Resolution set to fixed
- Component changed from selector to docs
comment:4 Changed 3 years ago by omegasharp
- Status changed from closed to reopened
- Resolution fixed deleted
$('input[name="foo[bar][blah]"]') works for both IE8 and FF3.5.8
However, I have a dropdown list, then:
$('select[name="foo[bar][blah]"]') works for IE8 but not for FF3.5.8.
Escape with
[
] does not work either.
Also tried and not working in FF (since it's a select tag):
$('[name="foo[bar][blah]"]')
Please follow the bug reporting guidlines and use jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

http://docs.jquery.com/Frequently_Asked_Questions#How_do_I_select_an_element_that_has_weird_characters_in_its_ID.3F