Clone elements, append them into array, $.map through array and append to NEW element
by lasha
HTML
<div id="ani-content" class="charityContent" style="display: block; ">
<div class="span">
<a class="view-all-link" href="/search/index/submit/Search?submit=Search&filters%5B0%5D=1" title="View all Animals & Envornment" tabindex="2">View all Animals & Envornment</a>
<p class="tab-desc">Preserve the environment, or protection for animals, both wild and domestic.</p>
<div class="cause-charity-containers">
<div class="cause-charity-container">
<a tabindex="3" href="/charity/view/ein/11-3499596/" of="" strays="" inc"="">Friends Of Strays Inc</a>
<p>
147-83 Grand Central Pkwy<br>
Briarwood, NY 11435<br>
EIN: 11-3499596 </p>
<a tabindex="4" href="/charity/view/ein/45-0707292/" &="" more="" animal="" rescue="" inc"="">Pibbles & More Animal…</a>
<p>
1706 Gates Ave<br>
Ridgewood, NY 11385<br>
EIN: 45-0707292 </p>
<a tabindex="5" href="/charity/view/ein/11-3540117/" touch="" inc"="">Loving Touch Inc</a>
<p>
PO Box 650404<br>
Flushing, NY 11365<br>
EIN: 11-3540117 </p>
</div><div class="cause-charity-container"> <a tabindex="6" href="/charity/view/ein/11-3444285/" and="" the="" strays="" inc"="">Bobbi And The Strays…</a>
<p>
10757 100TH St<br>
Ozone Park, NY 11417<br>
EIN: 11-3444285 </p>
<a tabindex="7" href="/charity/view/ein/26-2321902/" animals="" inc"="">For Animals Inc</a>
<p>
10946 122ND St<br>
S Ozone Park, NY 11420<br>
EIN: 26-2321902 </p>
<a tabindex="8" href="/charity/view/ein/11-3623088/" boulevard="" local="" development="" corp"="">Rockaway Boulevard Local…</a>
<p>
14211 Rockaway Blvd<br>
Jamaica, NY...
JavaScript
var browseCharitiesMobileContent = [];
$('.charityContent').each(function(i, el) {
browseCharitiesMobileContent.push($('#' + $(el).attr('id')));
// console.log(browseCharitiesMobileContent);
});
$.map(browseCharitiesMobileContent, function(val, i) {
var $contentToAdd = val.clone();
$contentToAdd.attr('id', function(i, val) {
return val + '-mobile';
}).appendTo('#browseCharitiesMobile');
});
$('#browseCharitiesMobile').find('.view-all-link').remove();
$('#select-charity-cause').change(function(e) {
var $currentCharityItem = $(this).val();
$('#browseCharitiesMobile .charityContent').hide();
$('#' + $currentCharityItem).show();
});