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
3 Answers
Reset to default 3if 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.