#9502 closed enhancement (invalid)
provide .hasData() method for consistency
Reported by: | Owned by: | ||
---|---|---|---|
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.
Change History (5)
comment:1 Changed 12 years ago by
Component: | unfiled → data |
---|---|
Owner: | set to [email protected]… |
Priority: | undecided → low |
Status: | new → pending |
comment:2 Changed 12 years ago by
Status: | pending → new |
---|
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
Resolution: | → invalid |
---|---|
Status: | new → closed |
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
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/
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/