Find the first element with the class and to fulfill the condition?

If the first element with the class of dg-center I need to satisfy the condition, unless there is something else I wrote a script but it is why it is always the last
$(document).ready(function() {
if($('.dg-container.dg-center').is(':first')){
$('.dady-body').css({
 backgroundImage: 'url(http://pucha2.kz/wp-content/themes/pucha/images/bg2.png)'
});
}
 else {
$('.dady-body').css({
 backgroundImage: 'url(http://pucha2.kz/wp-content/themes/pucha/images/bg-ambilight.png)'
});
}
 });

codepen-io
July 2nd 19 at 13:51
1 answer
July 2nd 19 at 13:53
so I have so
$(document).ready(function() {
if($('div').index('div.dg-center') == 0){
$('div.dady-body').css({background: 'red'});
} else {
$('div.dady-body').css({background: 'blue'});
}
});
a66bf01b59ac447ba75c0be5f5203a64.png4fe3836ef4774297bb99a19b25317b50.png

Find more questions by tags JavaScriptjQuery