0
<tbody>
                <tr class="d-flex">
                  <td>
                      <div class="form-check">
                        <label for="" class="form-check-label">
                          <input type="checkbox" class="form-check-input">
                        </label>
                      </div>
                  </td>
                  <td class="table__task__text">
                    <span class="notebookLine1 "></span>
                    <span class="notebookLine2 "></span>
                    <span class="tdLine"></span>
                      <span class="textchanger">Buy a milk</span>
                  </td>
                  <td class="ml-auto">
                      <img src="images/movearrow.png
                      " alt="movearrow" class="move">
                      <span class="utilites__lines1"></span>
                      <img src="images/pencil.png" alt="chengetext"  class="pencil">
                      <span class="utilites__lines2"></span>
                      <img src="images/trashbox.png" alt="deletetask">
                  </td>
                </tr>

                <tr class="d-flex">
                  <td>
                      <div class="form-check">
                        <label for="" class="form-check-label">
                          <input type="checkbox" class="form-check-input">
                        </label>
                      </div>
                  </td>
                  <td class="table__task__text">
                    <span class="notebookLine1 "></span>
                    <span class="notebookLine2 "></span>
                    <span class="tdLine"></span>
                      <span class="textchanger">Call Mam<span>
                  </td>
                  <td class="ml-auto" >
                      <img src="images/movearrow.png
                      " alt="movearrow" class="move">
                      <span class="utilites__lines1"></span>
                      <img src="images/pencil.png" alt="chengetext" 
                      >
                      <span class="utilites__lines2"></span>
                      <img src="images/trashbox.png" alt="deletetask">
                  </td>
                </tr>
$(document).ready(function(){

    $('.pencil').click(function(){
        var textarea = $('.textchanger');
        var text = prompt("Enter your task", "");
        textarea.text(text).children('tbody tr');
    });
});

Вообщем код работает,но,текст меняется для каждой td,а надо что бы менялся только для своей.Нажатие на кнопку которая меняет текст

Собственно результат

1 ответ 1

1

https://jquery-docs.ru/closest/

$(document).ready(function(){

  $('.pencil').click(function(){
    var $textarea =  $(this).closest('tr').find('.textchanger');    
    var $text = prompt("Enter your task", "");
    $textarea.text($text);
  }
});

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge you have read our privacy policy.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.