jquery get id of 3rd parent

JavaScript
$('#element1').parents().eq(2).attr("id");
Source

Also in JavaScript: