Open In App
Related Articles

jQuery context Property

Improve Article
Improve
Save Article
Save
Like Article
Like

The DOM node context contains the original passed to jQuery(), Which is a dom node context if there is no node passed then the context will be the document.

Syntax:

context

Examples: In this example, we are using the above-explained property.

html




<!DOCTYPE html>
<html>
 
<head>
    <meta charset="utf-8">
    <title>
        context demo
    </title>
    <script src=
    </script>
 
    <script>
        $(document).ready(function () {
            $("button").click(function () {
                $("ul")
                    .append("<li>" + $("ul")
                        .context + "</li>")
 
                    .append("<li>" + $("ul", document.body)
                        .context.nodeName + "</li>");
            });
        });
    </script>
</head>
 
<body>
 
    <h1 style="color:green;">
        GeeksForGeeks
    </h1> Context:
    <ul></ul>
    <button>Click</button>
 
</body>
 
</html>


Output:

jquery-55

Note:The context property was removed in jQuery version 3.0.


Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!

Last Updated : 11 Jul, 2023
Like Article
Save Article
Previous
Next
Similar Reads
Complete Tutorials