Skip to content
geeksforgeeks
  • 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
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • 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 remove() Method
Next article icon

jQuery prop() Method

Last Updated : 13 Jul, 2023
Comments
Improve
Suggest changes
Like Article
Like
Report

The prop() is an inbuilt method in jQuery that is used to set or return properties and values for the selected elements. When this method is used to return the property value, it returns the value of the FIRST matched element and when this method is used to set property values, it sets one or more properties for the selected elements.

Syntax :

$(selector).prop(para1, para2)

Parameters: It accepts two parameters which are specified below-

  • para1: It specifies the property.
  • para2: It specifies the value of the property in case of set.
  • Return Value:It returns the property and value set for the property for the selected element.
    jQuery code to show the working of prop() method:
  • html




    <!DOCTYPE html>
    <html>
     
    <head>
        <script src=
    "https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js">
        </script>
        <!-- jQuery code to show the working of this method -->
        <script>
            $(document).ready(function () {
                $("button").click(function () {
                    var $x = $("p");
                    $x.prop("color", "green");
                    $x.append(" Property is color and its value: "
                        + $x.prop("color"));
     
                });
            });
        </script>
        <style>
            div {
                width: 250px;
                padding: 10px;
                height: 100px;
                border: 2px solid green;
            }
        </style>
    </head>
     
    <body>
        <div>
            <p></p>
            <br><br>
            <!-- click on button this method -->
            <button>Click Here!</button>
        </div>
    </body>
     
    </html>
     
     

    Output:

    jQuery-99



    Next Article
    jQuery remove() Method

    K

    kundankumarjha
    Improve
    Article Tags :
    • JavaScript
    • JQuery
    • Web Technologies
    • jQuery-HTML/CSS

    Similar Reads

    • jQuery addClass() Method
      The addClass() method is an inbuilt method in jQuery that is used to add more properties to each selected element. It can also be used to change the property of the selected element. This method can be used in two different ways: 1) By adding a Class name directly: Here, the Class name can be used d
      2 min read
    • jQuery after() Method
      The after() method is an inbuilt function in jQuery which is used to insert content, specified by the parameter for each selected element in the set of matched elements. Syntax: $(selector).after(A);Parameter: It accepts a parameter "A" which is either a content or function passed to the method. Ret
      1 min read
    • jQuery append() Method
      The append() method in jQuery is used to insert some content at the end of the selected elements. Syntax: $(selector).append( content, function(index, html) ) Parameters: This method accepts two parameters as mentioned above and described below: content: It is a required parameter and is used to spe
      2 min read
    • jQuery appendTo() Method
      The appendTo() method is an inbuilt method in jQuery that is used to insert HTML element at the end of the selected element. Syntax: $(content).appendTo(selector)Here the element content specifies the content to be inserted. Parameters: It accepts a parameters "selector" that specifies the elements
      1 min read
    • jQuery attr() Method
      The attr() method in jQuery is used to set or return the attributes and values of the selected elements. Syntax: To return the value of an attribute:$(selector).attr(attribute)To set the attribute and value:$(selector).attr(attribute, value)To set attribute and value using a function:$(selector).att
      3 min read
    • jQuery before() Method
      The before() Method in jQuery is used to add the content before the selected element. Syntax: $(selector).before( content, function(index) )Parameters: This method accepts two parameters as mentioned above and described below: content: This parameter holds the content to be inserted before the eleme
      2 min read
    • jQuery clone() Method
      The clone() method is an inbuilt method in jQuery that is used to make a copy of selected elements including its child nodes, text, and attributes. Syntax: $(selector).clone(true|false)Parameters: This method accepts an optional parameter that could be either true or false specifying whether the eve
      2 min read
    • jQuery css() Method
      The css() method in jQuery is used to change the style property of the selected element. This method can be used in different ways. The css() method can be used to get/return the present value of the property for the selected element. Syntax: $(selector).css(property)or $(selector).css(property, val
      2 min read
    • jQuery detach() Method
      The detach() is an inbuilt method in jQuery that removes the selected elements from the DOM tree including all text and child nodes but it keeps the data and the events. Document Object Model (DOM) is a World Wide Web Consortium standard. This defines accessing elements in the DOM tree. Syntax: $(se
      1 min read
    • jQuery empty() Method
      The empty() method is an inbuilt method in jQuery that is used to remove all child nodes and their content for the selected elements. Syntax: $(selector).empty()Parameter: This method does not accept any parameter. Return Value: This method returns the selected element with the specified changes mad
      1 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