jQuery context Property

Introduction

Determine the context:

View in separate window

<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
  $("button").click(function(){

        $("div").append("<p>" + $("div").context + "</p>");
        //from   ww w  .  ja va  2s  .c  om
        document.getElementById("demo").innerHTML = $("div",document.body).context.nodeName;
  });
});
</script>
</head>
<body>
<p id="demo"></p>
<button>test</button>
<div></div>
<ul>
  <li>CSS</li>
  <li>HTML</li>
  <li>Javascript</li>
</ul>

</body>
</html>

The context property was deprecated in version 1.8 and removed in jQuery version 3.0.

The context property returns the original context passed to jQuery.

The returned value could be a DOM node context or if no node is passed, the document context.

context



PreviousNext

Related