Skip to main content

Bug Tracker

Side navigation

#9502 closed enhancement (invalid)

Opened June 02, 2011 09:09PM UTC

Closed June 04, 2011 05:21PM UTC

Last modified October 06, 2011 05:41PM UTC

provide .hasData() method for consistency

Reported by: Owned by:
Priority: low Milestone:
Component: data Version: 1.6.1
Keywords: Cc:
Blocked by: Blocking:

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.

Attachments (0)
Change History (5)

Changed June 02, 2011 10:15PM UTC by rwaldron comment:1

_comment0: Without adding a single line of code to jQuery and only costing you 1 character, instead of 3... \ \
component: unfileddata
owner: →
priority: undecidedlow
status: newpending

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

Changed June 03, 2011 06:51AM UTC by comment:2

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.

Changed June 04, 2011 05:21PM UTC by dmethvin comment:3

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.

Changed June 04, 2011 05:40PM UTC by rwaldron comment:4

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

Here's a clearer example:

Changed October 06, 2011 05:41PM UTC by rwaldron comment:5

#10441 is a duplicate of this ticket.