Easy Tutorial
❮ Sel Parent Descendant Event Mouseout ❯

jQuery.hasData() Method

jQuery Miscellaneous Methods

Example

Set data on an element and return the result of hasData

<p>Result: </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>

Definition and Usage

$ .hasData() function is used to determine if an element has any associated jQuery data.

Note: 1. This data is set using $.data(). If an element has no data (no data object or the data object is empty), this method returns false, otherwise it returns true.


Syntax

Parameter Description
element Element type A DOM element to be checked for data

jQuery Miscellaneous Methods

❮ Sel Parent Descendant Event Mouseout ❯