Using jQuery add the previous set of elements on the stack to the current set.
HTML Code :
<!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>
CSS Code:
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%; }
JavaScript Code :
$( "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" );
total answers (1)
start bookmarking useful questions and collections and save it into your own study-lists, login now to start creating your own collections.
HTML Code :
CSS Code:
JavaScript Code :