jQuery: The Write Less, Do More JavaScript Library

Ticket #2640 (new enhancement)

Opened 5 months ago

Last modified 5 months ago

CSS ~= attribute selector

Reported by: alexpkeaton Assigned to: anonymous
Type: enhancement Priority: minor
Milestone: 1.2.4 Component: core
Version: 1.2.3 Keywords: Selectors
Cc: Needs: Review

Description

There should be a ~= selector to select elements with an exact match where attribute values are separated by spaces. For example, suppose I have this HTML fragment:

<div class="button on"></div> <div class="button off"></div>

I would expect to select the "on" element with this:

$("div[class~=button][class~=on]");

The *= selector is similar, but fails in this example because the word "button" contains "on". Alternatively, this works:

$("div[class*=button on]");

But that requires attribute values to be in a specific order, which is not desirable.

Best regards,

Nathan Bryan

Attachments

Change History

Changed 5 months ago by alexpkeaton

This isn't necessary. I found using a selector like ".button.on" will work just fine. I guess I wasn't aware that was possible because IE6 doesn't support that so nobody typically does it that way.

Note: See TracTickets for help on using tickets.