This hasData() method in JQuery is used to determine whether an element has any jQuery data associated with it. This data may be text, event associated with element. There are two examples discussed below:
Syntax:
jQuery.hasData(element)
Arguments:
- element: This parameter is a DOM element which is to be checked for data.
-
Example: There is no data associated with <div> so the method returns false.
<!DOCTYPE HTML><html><head><title>JQuery | hasData() method</title></script></head><bodystyle="text-align:center;"><h1style="color:green;">GeeksForGeeks</h1><pid="GFG_UP"></p><div> This is DIV</div><br><buttononclick="Geeks()">Click here</button><pid="GFG_DOWN"></p><script>var el_up = document.getElementById("GFG_UP");var el_down = document.getElementById("GFG_DOWN");var $div = jQuery( "div" ), div = $div[ 0 ];el_up.innerHTML = "JQuery | hasData() method";function Geeks() {el_down.innerHTML = jQuery.hasData(div);}</script></body></html>chevron_rightfilter_none -
Output:
-
Example: There is a event associated with <div> so the method returns true.
<!DOCTYPE HTML><html><head><title>JQuery | hasData() method</title></script></head><bodystyle="text-align:center;"><h1style="color:green;">GeeksForGeeks</h1><pid="GFG_UP"></p><div> This is DIV</div><br><buttononclick="Geeks()">Click here</button><pid="GFG_DOWN"></p><script>var el_up = document.getElementById("GFG_UP");var el_down = document.getElementById("GFG_DOWN");var $div = jQuery( "div" ), div = $div[ 0 ];el_up.innerHTML = "JQuery | hasData() method";$div.on( "click", function() {} );function Geeks() {el_down.innerHTML = jQuery.hasData(div);}</script></body></html>chevron_rightfilter_none -
Output:
Recommended Posts:
- jQuery | jQuery.fx.interval Property with example
- jQuery | jQuery.fx.off Property
- jQuery | jQuery.support Property
- jQuery | jquery Property
- jQuery UI | position() Method
- JQuery | parseHTML() method
- jQuery | css() Method
- jQuery | add() method with Example
- jQuery | not() method with Examples
- jQuery | ajaxStart() Method
- JQuery UI | Progressbar method
- jQuery | get() Method
- jQuery | fadeIn() Method
- jQuery | delegate() Method
- jQuery | outerHeight() Method
- jQuery | event.isDefaultPrevented() Method
- jQuery | outerWidth() Method
- jQuery | before() Method
- jQuery | off() Method
- jQuery | html() Method
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

