简体   繁体   English

从具有 dom 的特定页面中删除标题 div

[英]remove header div from a specific pages with dom

I need to remove a section of the header with DOM for an A/B test.我需要使用 DOM 删除标题的一部分以进行 A/B 测试。 I need to do it just in two pages, but the problem is that I have the same classes in all the pages with the header and I don't want to remove it from all pages.我只需要在两页中完成,但问题是我在所有带有标题的页面中都有相同的类,我不想从所有页面中删除它。

The html structure is like this: html结构是这样的:

<nav class="navbar navbar-dark fiex-top">
<div class="header-logo">
<div class="progress-indicator">
</nav>
<section class="main-page-container">
<div class="container about-page">

I need to remove "progress-indicator"我需要删除“进度指示器”

I tried adding this code我尝试添加此代码

 const new1 = document.querySelector(".main-page-container");
    if (new1.classList.contains('about-page')) {
      document.querySelector(".progress-indicator").remove();
    } 

And this one和这个

   const removeheader = querySelector(".container.about-page");
if (removeheader.length > 1) {
document.querySelector(".progress-indicator").remove();
}

It was the idea I had, because inside I have a div with a different class in each page, but it didn't give me results, I don't know if it's possible to modify it like this这是我的想法,因为在里面我有一个div,每个页面都有一个不同的类,但是它没有给我结果,我不知道是否可以像这样修改它

I solved it with this code:我用这段代码解决了它:

 const removeheader1 = document.querySelector(".container.about-page");
        if (removeheader1.classList.contains('about-page')) {
          document.querySelector(".progress-indicator").remove();
        }

It seems that the problem was in the way I added the classes似乎问题出在我添加课程的方式上

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM