0
Hello, folks at Stackoverflow.
I try to make a textarea of a web page I am developing continuously check whether the typed text is the same or different from a predefined phrase, according to the javascript code and jquery below:
var atualiza = function(){
var texto = $(".campo-digitacao").text();
var frase = $(".frase").text();
if (texto==frase){
console.log("TEXTO IGUAL");
} else if (texto!=frase){
console.log("TEXTO DIFERENTE");
}
console.log("escreveu");
}
$(".campo-digitacao").on('input',atualiza());
However, I only get two notifications via console ("DIFFERENT TEXT" and "wrote"), as if the 'input' event only happens once, when loading the page, instead of it running every time the "input field" text changes. I tried to use other events like textchange and change, but I’m still in the same situation.
I didn’t even notice
.on()
was the same element :) Nicely caught. You can add a comment to the problem.on('input',atualiza());
? so the answer is complete+1
– Sergio
Thank you @Sergio
– BrTkCa