List input to HTML table cell



  • How do you put the selected value on the list in a cell where the list is located?

    $('#mySelect').on('change', function() {
      $(this).closest('tr').find('td')
        .text($(this).val());
    });
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
    

    <table>
    <tr>
    <td>test</td> <!-- Нужная ячейка -->
    <td>test2</td>
    </tr>

    <tr>
    <td>
    <select id="mySelect">
    <option>1</option>";
    <option>2</option>";
    </select>
    </td>
    <td>test
    </td>
    </tr>
    </table>



  • $('td > select').change(e => $(e.target).replaceWith(e.target.value));
    


Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2