I have 2 divs side by side and when one isn't there, I want the other to have a width of 100%.
while ($array = $query->fetch(PDO::FETCH_ASSOC)){
if (!empty($array['photoname'])){
echo '<div class=photo></div>';
}
echo '<div class=info></div>';
}
Here's my Javascript/jQuery:
$(document).ready(function() {
//check if photo div exists
if ($('.photo').length){
}else{
$('.info').css('width', '100%');
}
});
So if there is no photo div I want the info div to get a width of 100%. How can I achieve this?
UPDATE
If I don't have any photo divs showing, the above works and sets info divs to 100%. But when I have a photo div anywhere on the page, then none of the info divs are set to 100% even if they dont have a photo div next to them.