la función en el contenido cargado de ajax se ejecuta después de la eliminación también
Frecuentes
Visto 169 veces
0
mi pagina html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><script src="js/jquery.js"></script>
<script>$(function(){
$("button:first").click(function(){
$("#aja").load("ajax.html");});
$("button:last").click(function(){
$("#aja").remove();});
});
</script>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<body>
<button>Load page</button><button id="rem">Remove ajax content</button>
<div id="aja"></div>
</body>
</html>
and ajax.html code
<body>
<script>$(function(){
cool();});
function cool(){
$("button:last").after("Hello");
setTimeout("cool()",10000);}
</script>
</body>
Now when i load ajax.html it cool() function runs and keeps on adding hello to last button .The problem is when i remove the ajax loaded content with second button,cool() function which is removed keeps on running .But i want the cool function to stop after removal of ajax content
2 Respuestas
0
Checking on existence of #aja
block may help:
function cool() {
if ($("#aja").length == 0) return;
$("button:last").after("Hello");
setTimeout("cool()", 10000);
}
contestado el 22 de mayo de 12 a las 18:05
0
You want to use clear timeout
contestado el 22 de mayo de 12 a las 18:05
No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas javascript jquery function or haz tu propia pregunta.
@Webtecher That's the first idea which came to my mind. However, the question is a bit strange :) - Visión
If you get any other idea then plz update in your will be accepted answer - user1432124
@Webtecher I doubt if I can give better idea. This one should work perfectly. - Visión