user3782715
user3782715

Reputation: 19

how to hide div tag using javascript with an If condition

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

Answers (1)

Murray O&#39;Brien
Murray O&#39;Brien

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

Related Questions