Hide div on specific pages with jquery [closed]

0

Good morning,

I have a problem to hide a div only on a specific page, in case it has a php file with include_once that includes header pages, but it has a specific page that does not need a div that is inside the header and I want hide, how could I do this with jquery.

    
asked by anonymous 11.04.2018 / 15:51

1 answer

2
$(function(){
  if (window.location.pathname == "meusite/url1php"||window.location.pathname == "meusite/diretorio/url2.html"||window.location.pathname == "url3.html") {
        $('#umadiv').hide();
  } else {
        $('#umadiv').show();
  }
});

No script

You can also define a class in the <body> element indicating the current page. So if you're 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

  }
    
11.04.2018 / 16:03