But when it is replaced I cant focus there cursor. Maybe it triggers click event again and input field constantly is empty after click in input. What could be the solution?
Hi @SerhiiNuzhnyi You have many mistakes on your js codes
$(document).ready(function() { // <= https://developer.mozilla.org/tr/docs/Web/JavaScript/Reference/Statements/block
$(document).on("click", ".name, .email, .phone, .city", function() {
// in this scope this means your html document
$(this).off( "click" ); // this will remove click events on you codument
$(this).empty();
$(this).html("<input type='text'>").focus();
});
});
You should use more specific selectors not => $(document) like => $('.button')
Well. Here this means clicked element. I tested. If this means html document why $(this).empty(); wont empty entire document but only clicked element? $(this).off( "click" ) - doesnt remove click events at all.
The problem is when I want to return after I clicked another element to previous element and click on it second time it wont react to click. This because I use .off(event) but I must use it to avoid dissapearing text in input when I try to click inside input field. I know it s a bit hard to understand I can explain later.
Yes elements are loaded dynamically and I suppose event listener is added to each element from class list.
I would like to have no event listener on new added input but after click on it input field become empty so I assume that event is called again after click and empty the field.. And with this off() method I can click on input with no event and type text. But after click on another element I cant return to this because off() method remove listener.