Latest web development tutorials

jQuery.hasData () method

jQuery Misc Methods jQuery Misc Methods

Examples

Setting data elements returned hasData results

<P> Results: </ p> <script> $ (function () { var $ p = jQuery ( "P" ), P = $ p [ 0 ];. $ P append ( jQuery. hasData ( p ) + " " ); // False $. Data ( p, "testing", 123 );. $ P append ( jQuery. hasData ( p ) + " " ); // True $. RemoveData ( p, "testing" );. $ P append ( jQuery. hasData ( p ) + " " ); // False $ P. On ( "Click", function () {} );. $ P append ( jQuery. hasData ( p ) + " " ); // True $ P. Off ( "Click" );. $ P append ( jQuery. hasData ( p ) + " " ); // False }) </ Script>

try it"

Definition and Usage

$ .hasData ()Function is used to determine whether there is an element of data related to jQuery.

Note: 1. The data is to use $ .data () settings. If an element has no data (no data or data objects is empty), the method returns false, otherwise it returns true.
2. If there is no data on the object element, $. HasData (element) is not created or associated with a data object.


grammar

$.hasData( element )

参数 描述
element Element类型 一个用于进行数据检查的DOM元素


jQuery Misc Methods jQuery Misc Methods