Bug Tracker

Opened 12 years ago

Closed 12 years ago

Last modified 11 years ago

#9502 closed enhancement (invalid)

provide .hasData() method for consistency

Reported by: [email protected] Owned by: [email protected]
Priority: low Milestone: 1.next
Component: data Version: 1.6.1
Keywords: Cc:
Blocked by: Blocking:

Description

In the data category, all methods (queue, dequeue, data and removedata) have a jQuery.method() and .method() version, except for hasdata.

hasData should also be available in the latter format.

jQuery(element).hasData(key) returns boolean, true if key data field is set on element.

this would be a convenient way to avoid reference errors and having to check the value.

http://jsfiddle.net/L62U2/

Change History (5)

comment:1 Changed 12 years ago by Rick Waldron

Component: unfileddata
Owner: set to [email protected]
Priority: undecidedlow
Status: newpending

Without adding a single line of code to jQuery and only costing you 1 or 2 characters, instead of 3...

http://jsfiddle.net/rwaldron/3EyaP/

Last edited 12 years ago by Rick Waldron (previous) (diff)

comment:2 Changed 12 years ago by [email protected]

Status: pendingnew

I think I understand what you're saying, but your example is flawed - at least in chrome -, all tests return true but only the second should.

comment:3 Changed 12 years ago by dmethvin

Resolution: invalid
Status: newclosed

jQuery.hasData() is *only* meant to determine if a data object exists on an element at all and says nothing about whether a particular data key exists inside the data object.

I don't think the described functionality is needed, and it's easy to add yourself if you want it -- or just check for the data being undefined. We certainly wouldn't want to call it .hasData() since that would be confusing.

comment:4 Changed 12 years ago by Rick Waldron

Look closer... 1 & 3 have negation operators at the front of the expression. #2 had double negation.

Here's a clearer example: http://jsfiddle.net/rwaldron/3EyaP/5/

comment:5 Changed 11 years ago by Rick Waldron

#10441 is a duplicate of this ticket.

Note: See TracTickets for help on using tickets.