简体   繁体   English

如何使用jQuery在伪内容后删除元素

[英]How to remove element after pseudo-content with jQuery

I am working on the following code.我正在处理以下代码。 How can I remove the pseudo content after the .house on click event using jQuery?如何使用 jQuery 在.house on click 事件之后删除伪内容?

 $('.remove').on('click', function() { $('.house::after').css('display', 'none'); });
 .house { position: absolute; right: 0px; width: 0; height: 0; border-style: solid; border-width: 0 80px 80px 0; border-color: transparent red transparent transparent; } .house::after { position: absolute; content: ""; width: 80px; height: 80px; background: url("http://i.imgur.com/nceI30v.png"); background-repeat: no-repeat; background-position: 75% 40%; }
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div class="house"></div> <button class="remove">Remove Pseudo</button>

Try this code...试试这个代码...

 $('.remove').on('click', function() { $('.house').addClass('removing'); });
 .house { position: absolute; right: 0px; width: 0; height: 0; border-style: solid; border-width: 0 80px 80px 0; border-color: transparent red transparent transparent; } .house::after { position: absolute; content: ""; width: 80px; height: 80px; background: url("http://i.imgur.com/nceI30v.png"); background-repeat: no-repeat; background-position: 75% 40%; } .removing:after{ display:none }
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div class="house"></div> <button class="remove">Remove Pseudo</button>

You should add new class by click .eg: house_without and css:您应该通过单击添加新类。例如:house_without 和 css:

.house_without:after {
  content: none; /* may be add !important */
}

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

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