Skip to main content

Bug Tracker

Side navigation

#15091 closed bug (notabug)

Opened May 14, 2014 03:21AM UTC

Closed May 14, 2014 01:22PM UTC

jQuery reports error when selector's attribute is empty

Reported by: kennykwok Owned by:
Priority: undecided Milestone: None
Component: unfiled Version: 1.11.1
Keywords: selector Cc:
Blocked by: Blocking:
Description

jsFiddle: http://jsfiddle.net/L5gHQ/

Both buttons should be working properly under jQuery 1.11.0 or before.

In latest 1.11.1, the "Default" button strictly reports Javascript error (and this potentially break existing web site badly after upgrade)

I'm not sure if we should we consider this as a bug. It is a deal breaking issue, anyway, when considering upgrading jQuery.

Attachments (0)
Change History (2)

Changed May 14, 2014 04:13AM UTC by rwaldron comment:1

status: newopen

I can confirm that this no longer works in 1.x, but what you're doing is just wrong.

1. jQuery docs clearly state that attribute selector must have a quoted value:

Attribute values in selector expressions must follow the rules for W3C CSS selectors; in general, that means anything other than a valid identifier should be surrounded by quotation marks. double quotes inside single quotes: $('a[rel="nofollow self"]') single quotes inside double quotes: $("a[rel='nofollow self']") escaped single quotes inside single quotes: $('a[rel=\\'nofollow self\\']') escaped double quotes inside double quotes: $("a[rel=\\"nofollow self\\"]")

2. The correct way to set a "default" is to use the selected attribute: http://jsfiddle.net/rwaldron/VLVRr/

@timmywil or @gibson042 does this issue look familiar?

Changed May 14, 2014 01:22PM UTC by gibson042 comment:2

resolution: → notabug
status: openclosed

This is a direct consequence of fixing #14793 (and even a problem case identified therein); observe the Syntax error, unrecognized expression: option[value=] exception. To do what you want, just quote the attribute values: http://jsfiddle.net/L5gHQ/8/