11

I'm 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 line that changes the css style of the element involved.

How do i go about doing this?

Anyone have any suggestions / examples of how I could implement a PHP if/else and change css styles with jQuery inside the PHP if/else statement?

1
  • 4
    You could just output the CSS in the page head, inside a <style> tag - no need for jQuery then Commented Jan 13, 2013 at 13:10

2 Answers 2

33

You can echo the HTML for a style element and throw the CSS inside that.

else {
    echo '<style type="text/css">
        #id-element {
            display: none;
        }
        </style>';
}
Sign up to request clarification or add additional context in comments.

Comments

6

Reckon 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; ?>

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.