I’m trying to get the src attribute of an image that has been added to the page after it has loaded, but the result keeps coming back undefined.
$('#qtr').change(function() {
data = {
'img': $('#edit_image').attr('src'),
'degrees': '90'
};
$.post('/ajax/ajax_images/rotate', data, function(response) {
if (response.error != 0) {
alert('Unable to rotate image');
}
else {
$('#edit_image').attr('src', response.html);
new_image = response.html;
var start = new_image.lastIndexOf('/') + 1;
new_image = new_image.substr(start);
}
}, 'json');
});
$('#edit_image') is the newly created image. Where am I going wrong?
The problem is once the DOM is loaded any modification to your DOM, jquery needs to be explicitly told about the changes . So use a call back function look in to .bind() or .live() depending on your jquery version.