在“结果”页面上隐藏CSS类

时间:2018-05-19 11:26:59

标签: javascript css

我试图仅在页面结果上隐藏此类“mediad rh-flex-right-align”。这个类必须出现在除我已实现javascript方法隐藏它的主页之外的每个其他页面上。

这里是从主页隐藏它的代码:

<script>
        if (window.location.href == "https://www.comparer-acheter.fr/"){
document.getElementsByClassName("rh-flex-left-align")[0].style.display = 'none';
}
</script>

我正在搜索代码以隐藏此https://www.comparer-acheter.fr/product-search/上的CSS类以及获取此路径的所有页面(/ product-search“)(例如https://www.comparer-acheter.fr/product-search/?s=test&post_type=product):

<script>
        if (window.location.href == "https://www.comparer-acheter.fr/")
        if (window.location.href == "https://www.comparer-acheter.fr/product-search/") {
document.getElementsByClassName("rh-flex-left-align")[0].style.display = 'none';
}
</script>

显然我没有使用正确的代码.. 很高兴听到你能帮忙!

弗洛

1 个答案:

答案 0 :(得分:1)

使用它:

if(location.href.split(location.host)[1].startsWith("/product-search")) {
    // set to display none
    document.getElementsByClassName("rh-flex-left-align")[0].style.display = 'none';
}

您可能需要使用window.location.href ...