Removing data from a div with JQuery

-1

I need to remove the information that is inside one or remove the div from my web page with JQuery, I tried to use the code:

    $("#myid").html("");

and also

    $("#myid").remove();

None of the solutions worked, is there any other way?

    
asked by anonymous 30.10.2017 / 05:58

1 answer

0

Here are some examples of how to remove a div or remove content from it:

1st Remove div when clicking button using remove() method:

$("#removerDiv").click(function(){
    $('#divteste').remove();
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><divid="divteste" style="border:1px solid">
	<p>Conteúdo da DIV a ser removida</p>
</div>

<br>
<button id="removerDiv" type="button">Remover DIV</button>

2º Remove the contents of div while keeping it the same as clicking the button with the html("") method:

$("#removerConteudo").click(function(){
	$('#divteste').html("");
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><divid="divteste" style="border:1px solid">
	<p>Conteúdo da DIV</p>
</div>
<br>
<button id="removerConteudo" type="button">Remover Conteúdo</button>

3º Remove the contents of div by holding it down by clicking the button with empty() method:

$("#removerConteudo").click(function(){
	$('#divteste').empty();
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><divid="divteste" style="border:1px solid">
	<p>Conteúdo da DIV</p>
</div>
<br>
<button id="removerConteudo" type="button">Remover Conteúdo</button>

In the three examples above, I called the function to remove the div or remove the contents of it id from div . In jQuery , to call an element by id it is used the syntax #idDoElemento .

I think your code did not work because you forgot to import the jQuery library into the head of the page:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
    
30.10.2017 / 10:10