I am trying to find parent form from element using code below:
<form id="f1" action="action1.html">
form1 <button id="btn1" onclick="testaction(this); return false;" >test form 1</button>
</form>
<script type="text/javascript" >
function testaction(element) {
var e = $(element.id);
var form = e.parent('form');
alert(form.id); // undefined!!
alert(form.action); // undefined!!
alert(document.forms[0].action); //http://localhost/action1.html
}
</script>
It should be something really simple.... Thanks in advance
.parent
only gives the immediate ancestor.$(element)
instead of$(element.id)
.btn1.form
?