0

index.html と header.html の 2 つのページがあります。

index.html

<body>
  <div id="tpHeader"></div>
  <script>
    $(function(){
      $("#tpHeader").load("header.html");
    });
  </script>
</body> 

header.html

<div id="con1">
content 1
</div>
<div id="con2">
content 2
</div>

だから..ファイル index.html をブラウザで表示すると、次のようになります

<div id="tpHeader">
  <div id="con1">
    content 1
  </div>
  <div id="con2">
    content 2
  </div>
</div>

今、私は index.html で js または jquery を使用して #con2 を非表示にしたいと考えています。つまり、 index.html にいくつかのコードを記述したいと考えています。これにより、id="con2" を持つ要素が非表示になります。

私が試してみました

index.html

<body>
  <div id="tpHeader"></div>
  <script>
    $(function(){
      $("#tpHeader").load("header.html");
      $("#con2").hide(); // but this is not working 
    });
  </script>
</body> 

また、私は使用してみました

document.getElementById("con2").style.display = "none";

それらのどれも機能していません..plsは私を助けます

4

1 に答える 1