Changing CSS styles using PHP and jQuery

I am executing a PHP if / else statement.

However, I want the code to do something like this:

<?php if ($condition == true){ echo 'ITS TRUE!'; }else { #id-element.css('display':'none'); } ?> 

Note that the ELSE statement executes a jQuery string that changes the css style of the associated element.

How can I do it?

Does anyone have any suggestions / examples of how I can implement PHP if / else and change css styles using jQuery inside a PHP if / else statement?

+7
source share
2 answers

You can repeat the HTML for the style element and throw CSS in it.

 else { echo '<style type="text/css"> #id-element { display: none; } </style>'; } 
+23
source

Consider that you could do something like this:

 <?php if ($condition == true): echo 'ITS TRUE!'; else: ?> //put whatever html/style/script you want here, for example <script> $( '#id-element' ).css('display', 'none'); </script> <?php endif; ?> 
+3
source

All Articles