jQuery.hasData( element )Returns: Boolean
Description: Determine whether an element has any jQuery data associated with it.
-
version added: 1.5jQuery.hasData( element )
-
elementType: ElementA DOM element to be checked for data.
-
jQuery.hasData()
method provides a way to determine if an element currently has any values that were set using jQuery.data()
. If there is no data object associated with an element, the method returns false
; otherwise it returns true
.
jQuery.hasData(element)
is that it does not create and associate a data object with the element if none currently exists. In contrast, jQuery.data(element)
always returns a data object to the caller, creating one if no data object previously existed.
.on()
, .bind()
, .live()
, .delegate()
, or one of the shorthand event methods also associates a data object with that element.
Example:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
|