简体   繁体   English

div重新加载时如何隐藏元素

[英]How to hide an element when a div reloads

When the page finishes loading another load event is fired within a div tag. 页面加载完成后,将在div标签中引发另一个加载事件。 So, the DOM within this div tag is refreshed after the page has loaded. 因此,该div标签中的DOM在页面加载后将刷新。 When the div tag is refreshed it displays html id like to hide. 刷新div标签后,它会显示html id以便隐藏。 When I try to hide them when the page loads they are still there. 当我在页面加载时尝试隐藏它们时,它们仍然存在。 I have tried this code: 我已经试过这段代码:

$(function () {
    $('.myresults-button-exclude').hide();
});

This code does not work when the page loads 页面加载时此代码不起作用

Can't you just do this in CSS? 您不能只在CSS中执行此操作吗?

.myresults-button-exclude { 
   display: none
}

Then just use JS when you need to show it... $('.myresults-button-exclude').show(); 然后在需要显示时使用JS ... $('.myresults-button-exclude').show();

you could just hide them in a css file by default. 您可以将它们默认隐藏在一个CSS文件中。

<style>

    .myresults-button-exclude { display: none }

</style>

为什么不通过显示属性将类放在要隐藏的元素上:CSS中没有该类?

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

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