Remove all but first element

by Dan Mathisen

HTML

<div class="parent">
    <a href="#">one</a>
    <a href="#">two</a>
    <a href="#">three</a>
</div>

<div class="parent">
    <a href="#">one</a>
</div>

<div class="parent">
    <a href="#">one</a>
    <a href="#">two</a>
</div>

JavaScript

// The goal is to remove all but the first child element ('one')
// This works, but I feel it could be written better, maybe without 'each' or with vanilla JS

//$('.parent').each(function () {
//    $(this).find('a').not(':first').remove();
//});

$(".parent a:not(:first-child)").remove();