Answer the question
In order to leave comments, you need to log in
How to rewrite this code and organize the function?
Hello colleagues. Recently started working with jQuery and JS in general. I wrote this code:
The bottom line is that when you click on the input, a button pops up. I wonder how you can shorten / rewrite the code? Considering that there will be 20 such inputs.
And why doesn't the on('change') function work? If I want the button to appear only when the input is written.
I will be very grateful for the answers and recommendations!
Answer the question
In order to leave comments, you need to log in
Hang a common handler on the form and combine all buttons with 1 class ( .send_button ). Buttons, by the way, should be placed in .form_group , it will be more logical. And then:
$("form").on("focus", ".form_group > input", function(){
$(this).next(".send_button").fadeIn();
}).on("blur", ".form_group > input", function(){
$(this).next(".send_button").fadeOut();
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question