Proper way to check for particular .data() value in a jQuery object?

jquery

Solution

To obtain the property (e.g. for comparison), use `.data` with one argument:

$myObject.data('hello')

It returns the `undefined` value when the data does not exists.

Problem

I'd like to check to see if a jQuery data value has been applied to an object. For instance, code elsewhere may assign data to an object: ``` $myObject.data('hello','world'); ``` Elsewhere, I want to check to see if a value was given to the data property hello. What is the proper way to handle this? `.hasData` seemed like the obvious choice but appears to not work like 'hasClass' does in that you can't seem to pass a particular data element name to it.

Original source