0

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!

2
  • 1
    Does it help? w3schools.com/howto/howto_js_toggle_hide_show.asp Commented Apr 9, 2021 at 7:03
  • 1
    You don't need to use javascript because you don't want to toggle, you just don't want it to exist for these roles. Just use the condition on the part where you output the div and output them or not. Commented Apr 9, 2021 at 7:17

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.