0
When I click the remove button I remove all my line with this code, but when creating a new user it is not being heard by .click()
inserePlacar = () => {
let corpoTabela = $(".placar").find("tbody");
let usuario = $("#input-nome").val();
let numPalavras = $(".contador-palavras").text();
let linha = novaLinha(usuario, numPalavras);
corpoTabela.prepend(linha);
};
$(".botao-remover").click(function (event) {
event.preventDefault();
$(this).parent().parent().remove()
});
I’ve tried to put this in a function
being like this:
inserePlacar = () => {
let corpoTabela = $(".placar").find("tbody");
let usuario = $("#input-nome").val();
let numPalavras = $(".contador-palavras").text();
let linha = novaLinha(usuario, numPalavras);
linha.find(".botao-remover").click(removeLinha)
corpoTabela.prepend(linha);
};
removeLinha = (event) =>{
event.preventDefault();
$(this).parent().parent().remove()
}
But then it doesn’t remove anything.
Thiago, swap this part of the code for this and see if it works:
$(document).on("click", ".botao-remover", function (event) {
– Sam
Sam, either I didn’t understand and did wrong or didn’t mess, he behaved like the first example of my code.
– Thiago Maha
Dude, it should work :D... only the lines you add that aren’t removed?
– Sam
Exactly, only lines that are added by JS that are not removed. lines that are already in html can be removed
– Thiago Maha
It should work. It must be something else.
– Sam
Put in question this function
novaLinha
, I think it will help to analyze better.– Sam
can reproduce the problem in https://jsfiddle.net/ or here? so I can test and find a solution for your problem.
– HudsonPH
Before formulating an answer I would like to know of there are other components that use the
id = ".botao-remover"
and if there are other objects with this id if the eventclick
of these objects is and will always be the code of theremoveLinha
? I ask because the solution that I imagined with this data can generate the side effect of modifying undesirably an event click.– Augusto Vasques
https://jsfiddle.net/ThiagoMaha/cknx6mh1/4/ I think this is how you do it... I’m new to the studies and I’m not really familiar with the tools
– Thiago Maha