[removed] Update label content while typing inside of a parent input with Jquery

后端 未结 2 1234
忘掉有多难
忘掉有多难 2020-12-21 02:22

How to update with jquery the label of preview div when im typing inside of the parent input of edit div? Thank you.


        
               


        
相关标签:
2条回答
  • 2020-12-21 02:34

    you can not have the same ID in the tag "label" and the tag "input".

    <div id="preview">
      <label id="companyName" class="workExperience">
                                    This is my company
      </label>
    </div>
    <div id="edit">
      <label>Company Name: </label>
      <input type="text" id="companyNameInput" />
    </div>
    
    $(document).ready(function(e){
    
        $('#companyNameInput').bind('change', function(ev) {
    
            $(this).closest('#edit').prev().find('#companyName').html($(this).val());
    
        });
    
    
    });
    ​
    

    test

    0 讨论(0)
  • 2020-12-21 02:46

    You'd have to have something along these lines in your code:

    <script>
    $("#companyName").keyup(function () {
      var value = $(this).val();
      $(".workExperience").text(value);
    }).keyup();
    </script>
    

    However, I would NOT give them the same id value, as it might lead to some errors.

    Good luck!

    0 讨论(0)
提交回复
热议问题