0
With this code below when I click the button mat it brings me the data in a table. I would like to click on the button sp replace the contents of the table with another.
Code:
<button id="mat" class="button"></button>
<button id="sp"></button>
<table id="matriz">
</table>
<table id="saopaulo">
</table>
<script>
$(document).ready(function(){
$("#matriz").hide();
$("#mat").click(function(){
if($("#matriz").is(":visible")){
$("#matriz").hide();
} else{
$("#matriz").show();
}
$.ajax({
url: "../Conteudo/Matriz.html",
cache: false,
dataType: 'html'
})
.done(function(retorno) {
$("#matriz").html(retorno);
})
.fail(function() {
alert("Algo está errado");
});
});
$("#saopaulo").hide();
$("#sp").click(function(){
if($("#saopaulo").is(":visible")){
$("#saopaulo").hide();
} else{
$("#saopaulo").show();
}
$.ajax({
url: "../Conteudo/saopaulo.html",
cache: false,
dataType: 'html'
})
.done(function(retorno) {
$("#saopaulo").html(retorno);
})
.fail(function() {
alert("Algo está errado");
});
});
});
</script>
Which error shows?
– Fleuquer Lima
There is no error, only thing you send to replace it puts the content of the other button below what already has.
– KevinF
I don’t understand very well, is he creating another table? With which id?
– Fleuquer Lima
It does it in separate place because you’re telling it to, if you want it to replace use the same table, now if you want it to switch between tables, hide one and show the other
– Fleuquer Lima
You can only upload 1 single event
.html()on your page, to do this more than once, you have to use the event.delegate()– Ivan Ferrer
@Kevin. F You want to replace the content from which
tablewhen you click on#sp?– Igor Mello
The contents of the table
matrizby the content ofsaopaulo.– KevinF
@Kevin. F excuse the persistence but is to make sure to pick up the contents of the table
matrizand move on totablesaopaulo?– Igor Mello
No, it has 2 table contents
matrizwhen I click on it falls its contents, and when I click onspfalls the different content that issaopauloreplacing that ofmatriz. I’ll edit it in the code to get a better look. See if you understand better, each button brings a different content I just want to make the matrix disappear when the exit and vice versa.– KevinF