I have embedded some javascript within php code. This was necessary after checking some php session variable value, and upon result, I use some JS within php to decide if some elements will be shown or not. Here is an example:
<?php
if ($_SESSION['myVar']==2)
{ echo '<script type="text/javascript" >
document.getElementById("element1").style.visibility = "hidden";
document.getElementById("element2").style.visibility = "hidden";
</script>';
?>
The code works perfect for me. My question is : is the JS executed at the webserver(since it is embedded within php code) , initializing the page before it is sent to the client browser (and that what I think), or does the php portion run at the server, and the JS runs at the client later??
I know in normal situations the JS runs at the client browser,but was suspicious in this case,
I'm a junior programmer and any help is appreciated, thanks in advance.