Edit in JSFiddle

$(document).ready(function () {
    $(document).on('click', '#submit', function (event) {
        event.preventDefault();
        var parentId = $(this).parents(".level1").attr("id");
        alert(parentId);
    });
});
<div class="level1" id="level1_123">
    <div class="level2" id="level2_324">
        <div class="level3" id="level3_567">
            <div class="level4" id="level4_985">
                <input type="submit" value="Get Parent Id" id="submit" />
            </div>
        </div>
    </div>
</div>