andSelf() in jquery

It is used to add the previous set of elements on the stack to the current set.

<!DOCTYPE html>
<html>
<head>
  <style>
  p, div { margin:5px; padding:5px; }
  .border { border: 2px solid blue; }
  .background { background:pink; }
  </style>
  <script src="http://code.jquery.com/jquery-latest.js"></script>
</head>
<body>
  <div>
    <p>My name is Mahak Garg</p>
    <p>This is C# Corner</p>
  </div>
<script>
    $("div").find("p").andSelf().addClass("border");
    $("div").find("p").addClass("background");

</script>

</body>
</html>

Output:

1.png