I do not know why this will not work for me.
}).success(function(data){ if(data.status == 'success'){ // $("#useravatar").empty(); for(i = 0;i < data.id.length; i++){ $("#useravatar").prepend('<div id="av'+data.id[i]+'" class="avatar">'+data.avatar[i]+'</div>'); var dropDiv = $('#av'+data.id[i]); // Code from here dont work. No error. tried alert(data.id[i]); and is fine. dropDiv.css({ left: 130, top: -190, opacity: 0, display: 'inline' }).animate({ left: 5, top: 10, opacity: 1 }, 7000, 'easeOutBounce'); } } });
If I use only this code:
var dropDiv = $('#useravatar'); dropDiv.css({ left: 130, top: -190, opacity: 0, display: 'inline' }).animate({ left: 5, top: 10, opacity: 1 }, 7000, 'easeOutBounce');
will work with this div.
My question is why the first divs do not work? How can I make it release a div with animation?
EDIT:
I tried all the above code in the same file: but it did not work either (the second function is not called or does nothing).
function getchatuser() { $.ajax({ type: "POST", url: "../users/process.php", data: {getchatuser: "getchatuser"}, cache: false, dataType: 'json', async: false }).success(function (dat) { if (dat.status == 'success') { //$("#useravatar").empty(); for (i = 0; i < dat.id.length; i++) { $("#useravatar").prepend('<div id="av' + dat.id[i] + '" class="avatar">' + dat.avatar[i] + '</div>'); dropdivs(dat.id[i]); } } }); } function dropdivs(idDiv) { // alert(idDiv); ----------> just to try this and it works got 112 dropDiv = $('#av' + idDiv); dropDiv.css({ left: 130, top: -190, opacity: 0, display: 'inline' }).animate({ left: 5, top: 10, opacity: 1 }, 7000, 'easeOutBounce'); }
javascript jquery ajax
echo_Me
source share