jQuery .wrap () funktioniert nicht
Ich mache wahrscheinlich etwas falsch, aber ich habe alle möglichen Dinge ausprobiert und kann anscheinend keine Sammlung von jQuery-Objekten verpacken. Das Folgende gibt nur den Link-HTML-Code aus, der entpackt ist. Irgendwelche Ideen
$.each(sitemapSections, function(i) {
var $sitemapSection = $(sitemapSections[i]);
var $primary = $sitemapSection.find('a[data-level="1"]').wrap('<h3></h3>');
$dropdownSections[i].html($primary);
});
EDIT - hier ist das Markup (aufgeräumt):
<li id="product-solutions"><a href="#link" class="alpha grid-6">Products & Solutions</a>
<div id="ps-dropdown" class="dropdown-menu grid-20">
<div class="ps-dropdown-section">
</div><!-- .ps-dropdown-section -->
<div class="ps-dropdown-section">
</div><!-- .ps-dropdown-section -->
<div class="ps-dropdown-section">
</div><!-- .ps-dropdown-section -->
</div><!-- .dropdown-menu -->
</li>
UPDATE - Ich habe es verstanden! Die Kommentare, die parent () erwähnt haben, haben mir gefehlt. Hier ist der endgültige Code:
$.each(sitemapSections, function(i) {
var $sitemapSection = $(sitemapSections[i]);
var $primary = $sitemapSection.find('a[data-level="1"]').wrap('<h3></h3>').parent();
$dropdownSections[i].html($primary);
});