Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
<script src="https://code.jquery.com/jquery-git.js"></script>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>Using jQuery add the previous set of elements on the stack to the current set.</title>
</head>
<body>
<div class="left">
  <p><strong>Before <code>addBack()</code></strong></p>
  <div class="before-addback">
    <p>JavaScript</p>
    <p>jQuery</p>
  </div>
</div>
<div class="right">
  <p><strong>After <code>addBack()</code></strong></p>
  <div class="after-addback">
    <p>JavaScript</p>
    <p>jQuery</p>
  </div>
</div>
</body>
</html>
 
p, div {
    margin: 5px;
    padding: 5px;
    color: #c03199;
  }
  .border {
    border: 2px solid #360e9b;
  }
  .background {
    background: #cdc8b1;
  }
  .left, .right {
    width: 40%;
    float: left;
  }
  .right {
    margin-left: 2%;
  }
 
$( "div.left, div.right" ).find( "div, div > p" ).addClass( "border" );
 
// First Part
$( "div.before-addback" ).find( "p" ).addClass( "background" );
 
// Second Part
$( "div.after-addback" ).find( "p" ).addBack().addClass( "background" );
Output 300px

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
w3resourcepro
0viewers