Wrap each matching element in DIV
by Akram kamal
HTML
<ul class="one">
<li>Chelsea</li>
<li>Man City</li>
<li>Asernal</li>
<li>Corn</li>
</ul>
<ul class="two">
<li>Cheilsea</li>
<li>Man Ccity</li>
<li>Aserfnal</li>
<li>Corn</li>
</ul>
<div class="show-here">mmm</div>
<div class="matchBox">Match Box</div>
CSS
ul, li {
margin: 0;
padding: 0;
}
ul {
margin: 25px;
}
ul:first-of-type {
background:orange;
width: 150px;
}
ul:last-of-type {
background:green;
width: 150px;
}
li {
border-bottom: solid 1px white;
display: inline-block;
width: 100%;
padding-left: 10px;
}
JavaScript
$(document).each(function () {
var pMatch = $('.one li').map(function () {
return $(this).text()
})
var sMatch = $('.two li').map(function () {
return $(this).text()
})
$.each(pMatch, function (i, h) {
if (h === sMatch[i]) {
$(".one li").eq(i).appendTo('.matchBox');
$(".two li").eq(i).remove()
}
});
});