Bug Tracker

Opened 9 years ago

Closed 9 years ago

Last modified 7 years ago

#13623 closed bug (duplicate)

jQuery.data() does not work when using an attribute selector

Reported by: [email protected] Owned by:
Priority: undecided Milestone: None
Component: unfiled Version: 2.0b2
Keywords: Cc:
Blocked by: Blocking:

Description

It's my understanding that .data should get/set "data-" attributes.

However, after using .data("foo", "value") to set a particular attribute on an element, that element is not selectable using a "[data-foo=value]" selector. Using .attr instead works as expected.

jsFiddle: http://jsfiddle.net/AsJDb/1/

I'm pretty sure this exists downlevel as well.

Change History (3)

comment:1 Changed 9 years ago by Rick Waldron

Resolution: duplicate
Status: newclosed

Duplicate of #13234.

comment:2 Changed 7 years ago by Timwi

This bug is not a duplicate of #13234.

The jsfiddle provided in the bugreport clearly demonstrates the problem. I created a different one that exposes the same bug: http://jsfiddle.net/MG44D/

Please reopen this bug.

comment:3 Changed 7 years ago by dmethvin

As documented, the jQuery .data() API does not set data- attributes.

The data- attributes are pulled in the first time the data property is accessed and then are no longer accessed or mutated (all data values are then stored internally in jQuery). -- http://api.jquery.com/data/

Note: See TracTickets for help on using tickets.