Bug Tracker

Modify

Ticket #12214 (closed bug: invalid)

Opened 10 months ago

Last modified 10 months ago

$.data inconsistent with $().data

Reported by: dh10110@… Owned by:
Priority: undecided Milestone: None
Component: unfiled Version: 1.8rc1
Keywords: Cc:
Blocking: Blocked by:

Description

While testing jQuery 1.8 RC1, I encountered inconsistent behavior between $.data and $().data when reading inline data attributes.

When $.data is used first, the return value is always undefined. Once $().data is used with the same element, then $.data will work.

jsFiddle:  http://jsfiddle.net/t76Kc/6/

The specific use case I encountered this was inside a $().each function, trying to add specific data to each individual element. Since .each provides the element, I was trying to avoid an extra $() wrapper around the element if I did not need it.

I think this bug also existed in previous versions of jQuery.

Change History

comment:1 Changed 10 months ago by dmethvin

  • Status changed from new to closed
  • Resolution set to invalid

As documented, $.data doesn't read HTML data- attributes, by design.

Please follow the  bug reporting guidlines and use  jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

View

Add a comment

Modify Ticket

Action
as closed
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.