Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
<script class="jsbin" src="http://code.jquery.com/jquery-1.7.2.min.js"></script>
<meta charset=utf-8 />
<title>JS Bin</title>
<!--[if IE]>
  <script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<style>
  article, aside, figure, footer, header, hgroup, 
  menu, nav, section { display: block; }
  .wrap { border: 1px red solid; margin: 5px }?
</style>
</head>
<body>
  <p>Item 1</p>
<p class="item">Item 2</p>
<p class="item">Item 3</p>
<p class="item">Item 4</p>
<p>Item 5</p>
<p class="item">Item 6</p>
<p class="item">Item 7</p>
<p class="item">Item 8</p>
?
</body>
</html>
 
$(function() {
$("p.item")
.filter(function() {
    return !$(this).prev().is(".item");
})
.map(function() {
    return $(this).nextUntil(":not(.item)").andSelf();
})
.wrap('<div class="wrap" />');
});
Output

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

Dismiss x
public
Bin info
anonymouspro
0viewers