I have a javascript function that receives a dom element as a parameter. In this function I am trying to get to the closest ancestor ‘form’. I wanted to use:
function submit_form(obj)
{
var form1 = $(obj).closest("form");
alert (form1.id);
}
here obj is a dom element of submit type. I just don’t seem to get it working.
Could someone please help?
You want
The result of jQuery selection/traversal functions always is an array, possibly with one element only, but still an array. Index into the array to get actual DOM elements.
However, you can do this without jQuery as long as
objis an input/select/textarea element.For the sake of completeness, you could also stay within jQuery and do