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: shikakaa@gmail.com Owned by: shikakaa@gmail.com
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/

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... \ \ http://jsfiddle.net/rwaldron/3EyaP/1307052938739557
component: unfileddata
owner: → shikakaa@gmail.com
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/

Changed June 03, 2011 06:51AM UTC by shikakaa@gmail.com 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: http://jsfiddle.net/rwaldron/3EyaP/5/

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

#10441 is a duplicate of this ticket.