Reputation: 449
got a simple web site, in html. I do a simple function to move the image a user click to a different div ;
function setimage(){
$(".moving_img").click(function(){
$('#target').after( $(this));
});
}
but, after having moved the image ( also added a background change to yellow just to confirm it worked), my page suddenly reloads, console wont show me any errors, and I dont know what could cause this reload ... any idea why ? theres no ajax or any server-side code or any complicated pluggin I used ( i created everything I used and I'm no pro)
Upvotes: 1
Views: 97
Reputation: 160833
function setimage(){
$(".moving_img").click(function(){
$('#target').after( $(this));
return false; // add return false to prevent this.
});
}
Or use event.stopPropagation()
function setimage(){
$(".moving_img").click(function(e){
e.stopPropagation();
$('#target').after( $(this));
});
}
Upvotes: 2