[jQuery] select the parent recursively

[jQuery] select the parent recursively


current we have the html like following and I always want get element:
<span xmlns="asa"> started from the element <input>:
<span xmlns="asa">
<span>


<input value="" size="10" class="exercise-input exercise-input-
formula" name="1"/>




</span>
</span>
or
<span xmlns="asa">
<span></span>
<span>


<input value="" size="10" class="exercise-input exercise-input-
formula" name="1"/>




</span>
</span>
so the only fixed element in this html is the input element and input
has a far far parent <span xmlns="asa">.
Now if I want select this <span xmlns="asa">, can I use some recursive
method like:
var $replace=jQuery("input");
                    while($replace.attr("xmlns")!="asa"){
                        $replace=$replace.parent();
                        alert($replace.attr("xmlns"));
                    }
apparently this code above doesn't work, but it's my idea.
Anyone could help?