Change the background of a body with php and javascript

0

I have to change the image of the background that I assigned by css to a body depending on the validation that I do with an if in php, it would be something like this:

 if(!empty($userData)){
        echo "<script language='javascript'>"; 
        echo "document.body.style.backgroundImage='none'";
        //echo "$('.cuerpo').css('background-image', 'none');"; 
        echo "</script>";  

    }else{
        echo "no se cambia el background";
    }

I can not find how to do it, the idea is that the php validates a valid and if this is true do several things among others take the background to a body.

    
asked by Carlos Adrian Zapata Garcia 28.08.2017 в 19:20
source

1 answer

0

I recommend you do something like this:

if ( !empty($userData) ) {
    $bgNone = "<style type='text/css'>body {background-image:'none'}</style>";
    echo $bgNone;
}else{
   echo "no se cambia el background";
}
    
answered by 28.08.2017 в 19:31