最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Hide woocommerce-message in couple seconds - Stack Overflow

programmeradmin0浏览0评论

I tried to use this code to hide woomerce-message but it doesn't work.

  setTimeout(function() {
    $('.woomerce-message').fadeOut('fast');
}, 5000); // <-- time in mseconds

Do you any another solutions ? I tried to put this code into header.php and my template has space for Custom Header JavaScript Code but nothing works.

I tried to use this code to hide woomerce-message but it doesn't work.

  setTimeout(function() {
    $('.woomerce-message').fadeOut('fast');
}, 5000); // <-- time in mseconds

Do you any another solutions ? I tried to put this code into header.php and my template has space for Custom Header JavaScript Code but nothing works.

Share Improve this question edited Aug 15, 2017 at 12:40 hoijui 3,9442 gold badges38 silver badges45 bronze badges asked Mar 10, 2016 at 18:44 Róbert HoličkaRóbert Holička 351 silver badge7 bronze badges 1
  • 1 if the element is not there at the start, and appears randomly I assume you are going to have to check for when this message appears and then call the set timeout – user2950720 Commented Mar 10, 2016 at 18:52
Add a ment  | 

3 Answers 3

Reset to default 3

if the element pops up and is inserted into the dom randomly you can use an approach like this to remove it.

$(document).ready(function(){
  
   $(document).on('DOMNodeInserted', function(e) {
        if ($(e.target).is('.woomerce-message')) {
           
           setTimeout(function() {
             $('.woomerce-message').fadeOut('fast');
            alert("node fading"); 
           }, 5000);
        }
    });

   //object inserted after 2 seconds
   setTimeout(function(){
       $('<div class="woomerce-message">Test node inserted </div>').appendTo('body');
        alert("node inserted");
     },2000);
});
   
<script src="https://ajax.googleapis./ajax/libs/jquery/2.1.1/jquery.min.js"></script>

This worked for me.

    setTimeout(function() {
        $('.woomerce-message').fadeOut('fast') 
    }, 5000);

If you're using wordpress, try

    setTimeout(function() {
        jQuery('.woomerce-message').fadeOut('fast') 
    }, 5000);

This link may help you as well: jQuery | on click fade out and / or automatically fade out

It show the error when we use $(e.target). so ignoring the I have add tweak.

jQuery(document).on('DOMNodeInserted', '.woomerce-error,.woomerce-message', function(e) {
        setTimeout(function() {
            jQuery('.woomerce-error,.woomerce-message').fadeOut('fast');
        }, 6000);   
    });

Good luck.

发布评论

评论列表(0)

  1. 暂无评论