0

I have a table and each row contains select tag.

 <table>
   <tr>  
     <td><select onchange="function(this.value)">
           <option value="1">1</option>
            <option value="2">2</option>
        </select>
      <td>
 </tr>
<tr>  
     <td><select onchange="function(this.value)">
           <option value="1">1</option>
            <option value="2">2</option>
        </select>
      <td>
 </tr>
<table>

I want to pass the row index to the function(). How can it done?

Rose
  • 600
  • 5
  • 18

1 Answers1

0

You can traverse to tr element using closest along with .index() to get its index:

 $(this).closest('tr').index()
Milind Anantwar
  • 81,290
  • 25
  • 94
  • 125