1
It’s not duplicate that: How to run a jquery script when loading a page
I have a function that lists a content in div:
function listar() {
alert("listar"); // alert para saber se está sendo chamado
arquivo = "lista.php";
$.ajax({
url:arquivo,
success: function (textStatus) {
$('#iddiv1').html(textStatus);
}
});
}
I tried to load this function next to the page, but it doesn’t work:
$(document).ready(function(){
listar();
});
Also, I would like, while running the method listar(), be hidden from div.
Example:
$('#iddiv1').hide();
$('#iddiv2').show();
I tried so, but unsuccessfully:
$('#iddiv1').load(function() {
$('#iddiv1').hide();
$('#iddiv2').show();
});
Pq does not create the function already inside the Document.ready?
– LeAndrade
@Leandrade Isn’t the example I tried? Or is it wrong?
– rbz
Is loading jQuery before calling the
$(document).ready(function(){? If not, you probably have an error on the console.– Sam
@sam to
<script>of the function is in the<head>and the<script>jquery, at the end of the<body>... The order has to be reversed?– rbz
@sam is just... carrying!
– rbz
You can leave in the order you want to change the
$(document).ready(function(){fordocument.addEventListener("DOMContentLoaded", function(){– Sam