Reputation: 19
I want to hide a div tag after checking If condition. It means I checked session roles with If condition, and then make a javascript to hide a div tag. Can you guys have any code look similar like I want.
<?php
if ($_SESSION['role'] == 'Moderator' || $_SESSION['role'] == 'Editor') {
?>
<script type="text/javascript">
---code hidden div tag here
</script>
<?php }?>
something like this, because I don't want these roles "Moderator, Editor" see or do action on the div tag I want. Can you guys help me out. Thank you!
Upvotes: 0
Views: 191
Reputation: 47
The JS code would be like this:
//Get the div
var mydiv = document.getElementById("myDIV");
//Set display to none
mydiv.style.display = "none";
You can also do this without JavaScript like this:
<?php
if ($_SESSION['role'] == 'Moderator' || $_SESSION['role'] == 'Editor') {
?>
<div id="myDiv"></div>
<?php }?>
Place the div between the php if-statement
Upvotes: 1