Reputation: 59
There seem to be a ton of answered questions about hiding empty divs, but after I have tried several with no luck of it working I ask my own question. I have this section on my page to display various things in this case it's titles.
This is how it looks when there is a title to display:
This is how it looks when there is no title to display:
This is how what I want it to look like when there are no title to display:
Below is the code part that deals with this area the question concerns, the titles are being collected after how many points a member have and are collected from functions.php, so I want something that can read that there are no title to collect from functions.php and then instead of the ugly little square it shows No title if anyone has the answer to this I will be very happy, I have been on it for hours but with no success, I should say to that I am very much a novice when it comes to php and not even that when it comes to javascript and jquery.
<div id='dumb'>
<div id="assocpoint2">TITEL/S:</div><div id="assocpointprint2">
<? if($gender === 'Mare'){echo find_asda_title($horse);}elseif($gender === 'Stallion'){echo find_asda_title($horse);}elseif($gender === 'Gelding'){echo find_asda_title($horse);} ?>
<? if($gender === 'Mare'){echo find_asea_title($horse);}elseif($gender === 'Stallion'){echo find_asea_title($horse);}elseif($gender === 'Gelding'){echo find_asea_title($horse);} ?>
<? if($gender === 'Mare'){echo find_asja_title($horse);}elseif($gender === 'Stallion'){echo find_asja_title($horse);}elseif($gender === 'Gelding'){echo find_asja_title($horse);} ?>
<? if($gender === 'Mare'){echo find_sisf_title($horse);}elseif($gender === 'Stallion'){echo find_sisf_title($horse);}elseif($gender === 'Gelding'){echo find_sisf_title($horse);} ?>
<? if($gender === 'Mare'){echo find_aspa_title($horse);}elseif($gender === 'Stallion'){echo find_aspa_title($horse);}elseif($gender === 'Gelding'){echo find_aspa_title($horse);} ?>
<? if($gender === 'Mare'){echo find_aswa_title($horse);}elseif($gender === 'Stallion'){echo find_aswa_title($horse);}elseif($gender === 'Gelding'){echo find_aswa_title($horse);} ?>
</div></div>
Upvotes: 1
Views: 83
Reputation: 16831
You can handle the content of empty divs through css if you want:
Just target the empty div with the :empty
selector, and add a pseudo content to it:
#assocpointprint2:empty:after {
content: "No Title";
}
Upvotes: 0
Reputation: 360662
Most of that code seems to be utterly pointless/repetitive. Why not something more like:
$output = find_asda_title($horse) . find_asea_title($horse) . etc...
if (in_array($gender, array('Mare', 'Gelding', 'Stallion')) {
echo $output;
} else {
echo stuff to hide the div
}
Upvotes: 1