$(function(){
if (window.location.pathname == "meusite/url1php"||window.location.pathname == "meusite/diretorio/url2.html"||window.location.pathname == "url3.html") {
$('#umadiv').hide();
} else {
$('#umadiv').show();
}
});
Scriptless
You can also define a class in the element <body>
indicating the current page. So if you are on the index page, <body class='index'>
you can use CSS to hide specific elements.
body.index #umadiv { display: none; }
Example:
body.index #umadiv { display: none; };
<body class='index'>
<div id="umadiv">
kkkkkkk
</div>
Conteudo da pagina
</body>
You can also use the following scheme:
index php.
<php
$pagina="index";
.......
include_once "header.php";
.......
page1.php
<php
$pagina="pagina1";
.......
include_once "header.php";
.......
page2.php
<php
$pagina="pagina2";
.......
include_once "header.php";
.......
etc......
header.php
$ocultar = array("index", "pagina1", "pagina2");
if (!in_array($pagina, $ocultar)) {
//a div aqui
}
You’ll get better answers by giving people code they can use to reproduce the problem. https://answall.com/help/mcve
– user60252
Post the code please... Theoretically, you could search by ID, Class, etc. But each case is a case. Post the code...
– DiegoSantos
Sending a div unnecessarily via PHP to then hide in JS seems really strange (read gambiarra). Wouldn’t it be wiser to determine this on the same server? Or would it have some real justification for this, to better understand?
– Bacco
Gambiarra by Gambiarra... because only on the page you do not want the div you do not put in
<head>
one<style>
with display:None in #suadiv. So you don’t even need jQuery...– hugocsl
Easier would be in include to put IF path!= such { <html of div> } in php itself
– Bacco
I usually name the pages, putting at the beginning, before the <html tag>:
$pagename = "home";
... so it is easy to display or hide a specific content according to the variable$pagename
.– Sam