Edit in JSFiddle

$(function() {
    $('.target').parents().prepend($('<span class="label">parent</span> '));
    $('.target').parents('.selector').prepend($('<span class="label label-info">parent with selector</span> '));
});
<div class="well">
    <div class="well selector">
        .selector
        <div class="well">
            <div class="well selector">
                .selector
                <div class="well">
                    <strong class="target">.target</strong>
                </div>
            </div>
        </div>
    </div>
</div>

External resources loaded into this fiddle: