Bug Tracker

Opened 12 years ago

Closed 12 years ago

Last modified 12 years ago

#7581 closed bug (invalid)

.size() returns 1 on multiple objects

Reported by: [email protected] Owned by:
Priority: undecided Milestone: 1.5
Component: unfiled Version: 1.4.4
Keywords: Cc: anonymous
Blocked by: Blocking:



I don't know if this is a bug but I think so.

I tried to select <input name="names[]"/> with $('input[name=names
]').size() and it returns zero!

The same with an ID But then it returns 1. <input id="names"/> with $('#names').size()

It works if I do it with a class (.names)

Here is a demo: http://lab.codecookie.net/jquery_array_selector/


Change History (6)

comment:1 Changed 12 years ago by miketaylr

Resolution: invalid
Status: newclosed

This is not a bug, just an improperly escaped selector.

If you have a look at http://api.jquery.com/category/selectors/, you can see your exact example is covered:

"If you wish to use any of the meta-characters (#;&,.+*~':"^$[]()=>|/@ ) as a literal part of a name, you must escape the character with two backslashes. For example, if you have an an input with name="names[]"...", etc.

The #jquery IRC channel on Freenode or the support forums are also a great way to ask these types of questions.


comment:2 Changed 12 years ago by anonymous

yeah but if you had looked at my example you would have seen that I escaped it! $("input[name=names


comment:3 in reply to:  2 Changed 12 years ago by anonymous

ok here it looks not the right way.

I put two backslashes before each [ and ]


comment:4 Changed 12 years ago by addyosmani

Cc: anonymous added

If you would like us to re-open this ticket, please re-recreate your test case on jsFiddle.net so that we can evaluate it correctly. Note: the bug tracker is known to remove/interpret certain characters differently so characters you may have used in your original submission may not have been visible to us.

comment:5 Changed 12 years ago by [email protected]


here is the test case on jsFiddle.net: http://jsfiddle.net/FqXPb/

cu #dom

comment:6 Changed 12 years ago by jitter

Thanks providing the test case! jQuery requires the uses of quotes when using attribute selectors not matter if you escape or not the meta characters.

test case

Note: See TracTickets for help on using tickets.