nuet
nuet

Reputation: 219

How to hide a class in a condition

I want to hide a class in a list tag from being displayed in an if statement.

In css:

li.Popup.EditAccountLink

so it should be something like this but ofcourse this is not the good syntax....

 if(!= Gdn::Session()->UserID) {
  li class Popup.EditAccountLink {
    "display:none;"

  }

}

Can someone help me make it the right way?

Upvotes: 0

Views: 5452

Answers (2)

p0d4r14n
p0d4r14n

Reputation: 681

i'd do it like that:

<?php

$class='';

if (condition) {
  $class=' class="hidden"';
} else {
  $class=' class="whatever"';
}

echo '<div'. $class .'></div>';

?>

Upvotes: 1

Rizier123
Rizier123

Reputation: 59701

You could do something like this:

(So that you have 2 different classes in css and if the condition is true you only have to change the class attr. of the element)

An example (Not valid code):

PHP:

<?php

    if(condition) {
        echo "<div class='normal'>TEST</div>";
    } else {
        echo "<div class='hide'>TEST</div>";                                       
    }

?>

CSS:

.normal {
  display: inline;
}

.hide {
  display: none;
}

Hope you get the idea

Upvotes: 1

Related Questions