Use closest . He searches for the ancestors * of the element to find the first (closest) match.
$('#my_input').closest('form').attr('id');
* Note: the closest () is looking up starting from the current item, so it can match the current item.
nickf
source share