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.
To obtain the property (e.g. for comparison), use
.datawith one argument:It returns the
undefinedvalue when the data does not exists.