I would like to run a function when a div content(an image) is charged, I have been trying this with html().length and onChange, but onChange only works when page is loaded, thanks:
My code:
if (($("#zv1").html().length > 0) && ($("#zv1").change())){
//ion.sound.play("water_droplet_2");
alert("sound");
}
if (($("#zv2").html().length > 0) ) {
//ion.sound.play("water_droplet_2");
alert("sound");
}
if (($("#zv3").html().length > 0) && ($("#zv3").change())) {
//ion.sound.play("water_droplet_2");
alert("sound");
}
if (($("#zv4").html().length > 0) && ($("#zv4").change())) {
//ion.sound.play("water_droplet_2");
alert("sound");
}
if (($("#zv5").html().length > 0) && ($("#zv5").change())) {
//ion.sound.play("water_droplet_2");
alert("sound");
}
if (($("#zv6").html().length > 0) && ($("#zv6").change())) {
//ion.sound.play("water_droplet_2");
alert("sound");
}
if (($("#zv7").html().length > 0) && ($("#zv7").change())) {
//ion.sound.play("water_droplet_2");
alert("sound");
}
if (($("#zv8").html().length > 0) && ($("#zv8").change())) {
//ion.sound.play("water_droplet_2");
alert("sound");
}
AJAX example:
function sync_vitrasa(id){
$.ajax({
url: "/vitrasa_state/",
type:"GET",
data: {
id: id,
},success: function( data ) {
id="#zv"+id;
if($(id).html().length == 0){
$(id).html(data)
alert("sound");
}
else {
if($(id).html() != data) {
//ion.sound.play("water_droplet_2");
alert("image is already there");
}
}
}
});
}
Check if submit in another HTML is clicked:
$(document).ready(function() {
setInterval(function () {
$.ajax({
url : '/vitrasa/',
success : function(data){
$('#sub2').click(function() {
alert( "calling Ajax." );
sync_vitrasa(2);
});
}
});
}, 500);
});
PD: zvX is the div id for the HTML td that contais the image charged with AJAX