mkoryak
mkoryak

Reputation: 57928

attribute selectors contains meta-characters in jquery

In jquery 1.4.2 this was a valid selector:

$('input[name=test[0]]')

in jquery 1.6.2 it is not a valid selector, the docs state to escape special characters with \.

my question is, in what version did this happen, and can someone provide a link to a discussion of this change?

Upvotes: 0

Views: 400

Answers (1)

Matt
Matt

Reputation: 75317

The selector you posted does not work in jQuery 1.4.4, but does work in 1.4.2

See here for complete tests: http://jsfiddle.net/YPd4J/

Summary:

  • input[name=test[0]] error in 1.6.2, doesn't work in 1.4.4, works in 1.4.2
  • input[name="test[0]"] works in all versions
  • input[name=test\\[0\\]] works in 1.6.2 & 1.4.2, not in 1.4.4
  • input[name="test\\[0\\]"] works in all versions

I can remember the advise regarding escaping meta-characters been in the documentation as long as I can remember (and I've been using jQuery since 1.3.x)... maybe it was never officially supported, but just happened to work.

Edit: Did the tests for 1.4.4, and then saw you actually wrote 1.4.2... tests updated :P

Upvotes: 3

Related Questions