Bug Tracker

Opened 9 years ago

Closed 9 years ago

#15091 closed bug (notabug)

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:


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.

Change History (2)

comment:1 Changed 9 years ago by Rick Waldron

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?

comment:2 Changed 9 years ago by gibson042

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/

Note: See TracTickets for help on using tickets.