I know that I can remove an empty div using javascript, but is it possible using php?
I have a div that has several if statements that will fill the content of the div. If those terms aren't met I get up with an empty div, doing nothing. The div has a class, if that makes it any simpler.
Is this possible in php? Is there a .hide()
or .remove()
equivalent in php?
No, it's not possible to remove a created div with PHP.
What you can do is not create the div unless one of your if statements pass
No, PHP is a SERVER side language that only runs before the page is loaded the only way to hide a div is to give a hidden div in the html. You ill need javascript to hide it dynamicly.
PHP is a server scripting language,So it is not possible.
As the others have mentioned, this is not possible using a server-side language, unless you choose to not render the div at all in the first place. This is not necessarily a bad choice, but depending on what you are planning on doing (if you wanted to provide more of an explanation, please feel free to).
If you would prefer to do this client-side then you could use either vanilla javascript and remove the node from the DOM. Alternatively (probably a better idea) you could remove it using a one-liner using jQuery:
$(".yourDiv").remove();
Up to you - hope that helps!
You can however try out by including div inside if condition and closing it wherever it is appropriate,
this displays div if a particular condition is present
else doesn't include particular div in your code at all
For E,g
if(some condn..)
{
echo "<div>";
your code...
echo "</div>";
}
I have shown you the simple one using one if, but you can fix it up for any number of ifs
with little attention of opening and closing of DIV tags
Secondly Jquery is Equivalent to CSS
Jquery i.e $("#abc").hide();
css #abc{ display:none; }
etc i have given you just a sample but you can explore on...
using php, you can do it like this
<?php if(satisfy both $a and $b): ?>
<div>
<?php
if($a)
{
echo $a;
}
else if($b)
{
echo $b;
}
?>
</div>
<?php endif; ?>