how wrap div around two element with jquery
html, jquery
Solution
You can iterate through `h3` elements and using jquery .next() to select and the `ul` element with .andSelf() to include and `h3` element and finally .wrapAll() around a `div`:
$('h3').each(function() {
$(this).next('ul').andSelf().wrapAll('<div/>');
});
div {
border: solid 1px red;
}
h3 {
border: solid 1px green;
}
ul {
border: solid 1px yellow;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<h3>h3</h3>
<ul>ul</ul>
<h3>h3</h3>
<ul>ul</ul>
<h3>h3</h3>
<ul>ul</ul>
Problem
I have some pair of element, they are ``` <h3></h3><ul></ul> <h3></h3><ul></ul> <h3></h3><ul></ul> ``` I want to wrap a element (div) with jquery around all of this pair result should be ``` <div> <h3></h3><ul></ul> </div> <div> <h3></h3><ul></ul> </div> <div> <h3></h3><ul></ul> </div> ``` How can I achieve it with `jquery.wrap()`?