There is a function

indentRub: function() { $('.ab_form-col').on('input.ab_input--rubl', 'input.ab_input--rubl[type="text"]', function() { let lengthInputRub = $(this).val().length; // Подсчет символов в инпуте if (lengthInputRub >= 1) { $('.js-ruble-before').css('left', '210px'); } else { $('.js-ruble-before').css('left', '10px'); } }); }, 

On page 2 of these forms, the classes are also the same. It is necessary that the function is applied to 1 element, i.e. in which the value is entered. This is an input and near it a div with the class js-ruble-before to which the condition should apply. The problem is that the condition applies to all elements with a given class.

2 answers 2

You need to search for this , which in this case will be the current input field.

In the simple case, when an element with the class js-ruble-before is immediately after or immediately before, you can use the methods prev , next

 $(this).prev('.js-ruble-before') $(this).next('.js-ruble-before') 

Or it is necessary to rise to the form itself using the closest method, and search inside it using the find method

 $(this).closest('.ab_form-col').find('.js-ruble-before') 

    You did not have a correct handler.
    I used the " keyup " key release method ( description )
    As it has been correctly described in comments, it is necessary to proceed from this , it will be an input.ab_input - rub element . The if statement can be rewritten into 1 line using another operator (condition)? true: false .

    Example code: https://jsfiddle.net/bearwolf/y1j1sjng/2/

     $(document).on("keyup", ".ab_form-col input.ab_input--rub", function() { var _this = $(this); _this.closest('.ab_form-col').find('.js-ruble-before').css({left: _this.val().length>=1 ? '210px' : '10px'}); }); 
     form{ height:50px; margin-bottom: 20px; position:relative; } .js-ruble-before{ position:absolute; left:0; bottom:0; } 
     <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script> <form class="ab_form-col"> <input type="text" class="ab_input--rub"> <div class="js-ruble-before"> Что то... </div> </form> <form class="ab_form-col"> <input type="text" class="ab_input--rub"> <div class="js-ruble-before"> Что то... </div> </form>