简体   繁体   English

使用Jquery在页面加载中隐藏div

[英]To hide a div on Page Load using Jquery

I have some div in my code as mentioned below. 我的代码中有一些div,如下所述。 Through Jquery I want to hide div having class="redCategory redCap vertical". 通过jQuery,我想隐藏具有class =“ redCategory redCap vertical”的div。 My Jquery code to hide div is $(".redCap").hide(); 我要隐藏div的Jquery代码是$(".redCap").hide(); but after page load div is not getting hidden. 但是页面加载后div不会被隐藏。 What should be Jquery? 什么是Jquery? I want to hide div during page load. 我想在页面加载期间隐藏div。

<div class="redLinkContainer">

    <span class="accessibleText" aria-level="1" role="heading"></span>
    <div class="redCategory redHome adjacent"><a> href="https://example.com/">1</a></div>
    <div class="redCategory redContact adjacent"><a> href="https://example.com/">2</a>></div>
    <div class="redCategory Things adjacent"><a> href="https://example.com/">3</a></div>
    <div class="redCategory redCap vertical">
        <a class="red CategoryTitle redCategoryHeader" href="https://example.com/">4</a>
          </div>
     <div class="redCategory ManyThings adjacent"><a> href="https://example.com/">5</a></div>
    </div>

put hidden in the div: 隐藏在div中:

 <div class="redCategory redCap vertical" hidden> <a class="red CategoryTitle redCategoryHeader" href="https://example.com/">4</a> </div> 

Add this to css file 将此添加到css文件

.divHide{display:none;}
.divShow{display:block;}

Your HTML code: 您的HTML代码:

<div class="redLinkContainer divHide"></div>

when the page load div is hidden. 当页面加载div隐藏时。

<a> tag is wrong format. <a>标签格式错误。 Please use proper format 请使用正确的格式

<a class="red CategoryTitle redCategoryHeader" href="https://example.com/">4</a>

Please find the Below URL,(check your code) 请找到下面的URL,(检查您的代码)

https://jsfiddle.net/wg62c8j5/ https://jsfiddle.net/wg62c8j5/

I did some tests here and it work as expected. 我在这里做了一些测试,它按预期工作。

<script type="text/javascript">

 $(".redCap").hide();

</script>

<div class="redLinkContainer">

    <span class="accessibleText" aria-level="1" role="heading"></span>
    <div class="redCategory redHome adjacent"><a>   href="https://example.com/">1</a></div>
    <div class="redCategory redContact adjacent"><a> href="https://example.com/">2</a></div>
    <div class="redCategory Things adjacent"><a> href="https://example.com/">3</a></div>
    <div class="redCategory redCap vertical">
       <a class="red CategoryTitle redCategoryHeader" href="https://example.com/">4</a>
      </div>
  <div class="redCategory ManyThings adjacent"><a> href="https://example.com/">5</a></div>

Are you sure your JQuery library is being loaded ? 您确定要加载JQuery库吗?

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

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