I have some jQuery which animates the background colour of <div
> tags when hovered (and reverts them when no longer hovered).
$('.row').hover(function() {
$(this).stop().animate({
backgroundColor: "#000000"
}, 250 );
}, function () {
$(this).stop().animate({
backgroundColor: "#15181A"
}, 250 );
});
And I have an AJAX call on my page to load some additional <div
>s, like this:
$.ajax({
type : 'POST',
url : "ajax.php",
dataType : 'json',
data: {
query : $('#search').val()
},
success : function(data) {
if (data.error === true) {
// Error
} else {
$('#more').html(data.msg);
}
},
error : function(XMLHttpRequest, textStatus, errorThrown) {
// Error
}
});
The AJAX call effectively returns more <div
>s with a class of "row", but when they're hovered the jQuery doesn't animate their background colour. Is it possible to select these rows with jQuery, even thought they were loaded via AJAX?
EDIT: Here's what's returned by the AJAX call, ajax.php:
<?php
$return['error'] = false;
$return['msg'] = '<div class="row" style="background: #15181A;">A row...</div>';
$return['msg'] = '<div class="row" style="background: #15181A;">Another row...</div>';
$return['msg'] = '<div class="row" style="background: #15181A;">Another row...</div>';
echo json_encode($return);
return;
?>