Skip to content
geeksforgeeks
  • Tutorials
    • Python
    • Java
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
    • Practice Coding Problems
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • jQuery Tutorial
  • jQuery Selectors
  • jQuery Events
  • jQuery Effects
  • jQuery Traversing
  • jQuery HTML & CSS
  • jQuery AJAX
  • jQuery Properties
  • jQuery Examples
  • jQuery Interview Questions
  • jQuery Plugins
  • jQuery Cheat Sheet
  • jQuery UI
  • jQuery Mobile
  • jQWidgets
  • Easy UI
  • Web Technology
Open In App
Next Article:
JQuery hasData() method
Next article icon

JQuery hasData() method

Last Updated : 23 Jul, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

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. html
    <!DOCTYPE HTML>  <html>   <head>      <title>        JQuery | hasData() method     </title>           <script src="https://code.jquery.com/jquery-3.5.0.js">     </script>  </head>    <body style="text-align:center;">      <h1 style="color:green;">           GeeksForGeeks       </h1>      <p id="GFG_UP">      </p>     <div> This is DIV     </div>     <br>     <button onclick="Geeks()">          Click here      </button>            <p id="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>  
  • Output:


  • Example: There is a event associated with <div> so the method returns true. html
    <!DOCTYPE HTML>  <html>   <head>      <title>        JQuery | hasData() method     </title>           <script src="https://code.jquery.com/jquery-3.5.0.js"> </script>  </head>    <body style="text-align:center;">      <h1 style="color:green;">           GeeksForGeeks       </h1>      <p id="GFG_UP">      </p>     <div> This is DIV     </div>     <br>     <button onclick="Geeks()">          Click here      </button>            <p id="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>  
  • Output:



Next Article
JQuery hasData() method

P

PranchalKatiyar
Improve
Article Tags :
  • JavaScript
  • Web Technologies
  • JQuery
  • jQuery-Methods

Similar Reads

    jQuery ajax() Method
    The jQuery ajax() method is used to perform asynchronous HTTP requests, allowing you to load data from a server without reloading the webpage. It provides a flexible way to interact with remote servers using GET, POST, or other HTTP methods, supporting various data formats.Syntax:$.ajax({name:value,
    4 min read
    JQuery | isArray() method
    This isArray() Method in jQuery is used to determines whether the argument is an array. Syntax: jQuery.isArray( object ) Parameters: The isArray() method accepts only one parameter that is mentioned above and described below: object : This parameter is the object to test whether or not it is an arra
    2 min read
    jQuery | get() Method
    In jQuery .get() method loads data from the server by using the GET HTTP request. This method returns XMLHttpRequest object. Syntax $.get( url, [data], [callback], [type] ) Parameters url : String containing the URL at which request is to be sent data : This is an optional parameter that represents
    2 min read
    jQuery ajaxSetup() Method
    The ajaxSetup() method in jQuery is used to set the default values for future AJAX requests. Syntax: $.ajaxSetup( {name:value, name:value, ... } )Parameters: type: It is used to specify the type of request.url: It is used to specify the URL to send the request to.username: It is used to specify a us
    3 min read
    JQuery | isPlainObject() Method
    This isPlainObject() Method in jQuery is used to check to see if an object is a plain object. Syntax: jQuery.isPlainObject( obj ) Parameters: This method accept a single parameter that is mentioned above and described below: obj: This parameter holds the object that will be checked to see if it's a
    2 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences