4
Good morning gentlemen, I’m having a certain problem removing just one of the elements.
I have a textarea that adds paragraphs, the problem is being at the time of deleting, I want btn to delete only his father div and not the others, as there can be several paragraphs they are added as class, and that’s where the problem is, when I click on btn remove, it exclude all elements with the class. I’m using $(this) and Parent() but since I’m new with jquery I must be missing something, so I ask for the help of the companions! I thank you already! Hug!
$("#addParagrafo").click(function () {
var conteudo = $('#adicionarConsideracoesGerais').val();
$("#consideracoesGeraisParagrafos").append("<div class='painel-paragrafo'><textarea class='form-control paragrafoConsideracoesGerais' disabled rows='4'>" + conteudo + "</textarea><br><button type='button' class='btn btn-xs btn-default pull-right btn-remover' title='Remover este parágrafo'><i class='fa fa-minus'>Remov</i></button><br><br></div>");
$('.painel-paragrafo').on('click', ".btn-remover", function () {
$(this).parent().parent().find('.painel-paragrafo').remove();
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="col-md-12">
<div class="panel">
<div class="paragrafosConsideracoesGerais">
<ul id="consideracoesGeraisParagrafos">
</ul>
<textarea class="form-control" id="adicionarConsideracoesGerais"></textarea>
<div class="clearfix"></div><br>
<button class="btn btn-xs btn-default pull-right" type="button" title="Adicionar Parágrafo" id="addParagrafo"><i class="fa fa-plus">add</i></button>
</div>
</div>
</div>
Although your answer may be correct, it would be interesting to at least give an explanation of how you did to get the desired result
– MarceloBoni
Hello Marcelo, forgive my failure, is that I’m new here and I’m learning to use the tool, when I answered I used the button "Copy code snippet for the answer", from then on I just modified what I wanted and was afraid to add the explanation in the middle of the code and it did not execute.
– Abidias
What I did was change the code snippet $(this). Parent(). Parent(). find('.dashboard-paragraph'). remove();
– Abidias
For $(this). Parent(). remove();
– Abidias
@Abidias welcome to Sopt, just click the button edit just below your reply and add these details. You can add the information before the tags
<!-- begin snippet
, can also add as comments in codes// realizei tal alteração
just below the edit box has the preview of the answer/question. I suggest you make a tour to know more the site.– KaduAmaral
Thank you Kaduamaral for the clarifications, I will follow your guidelines.
– Abidias