简体   繁体   中英

I want to check if user is not logged in with PHP and then add a class to selector with jQuery

Checking if a user is logged in is no problem. But if the user is not logged in I want to add something like this:

$( "#tab-additional_information > table > tbody > tr:nth-child(1)" ).addClass( "jl_hidden" );

How do I embed this jQuery in a PHP if / else statement?

You can add PHP code in javascript like described below.

<script type="text/javascript">
<?php if($_SESSION['is_logged_in'] == TRUE): ?>
    $( "#tab-additional_information > table > tbody > tr:nth-child(1)" ).addClass( "jl_hidden" );
<?php endif; ?>
</script>

Please, let me know if it not works. Also, change session name depends on your code.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM