Get a form Id an attribute located in - Javascript jQuery Method and Property

Javascript examples for jQuery Method and Property:closest

Description

Get a form Id an attribute located in

Demo Code

ResultView the demo in separate window

<html>
 <head> 
  <meta name="viewport" content="width=device-width, initial-scale=1"> 
  <script type="text/javascript" src="https://code.jquery.com/jquery-1.8.3.js"></script> 
  <script type="text/javascript">
var handler = function(elem){
    console.log($(elem).closest('form').attr('id'))
};

      </script> 
 </head> /*w w  w. j a va 2  s .c  o  m*/
 <body> 
  <form id="formId"> 
   <div> 
    <input type="radio" onclick="handler(this)"> 
   </div> 
  </form>  
 </body>
</html>

Related Tutorials