<div id = "div1" class = "d1">
    <div id = "div2" class = "d2">
        <div id = "div3" class = "d3">
            <div id = "div4">
            </div>
        </div>
    </div>
</div>
<input type = "button" value = "Demo" id = "demo" />
<script type="text/javascript">
    $("#demo").live("click", function () {
        var div3 = $("#div4").parents(".d3");
        var div2 = $("#div4").parents(".d2");
        var div1 = $("#div4").parents(".d1");
    });
</script>