when I refresh the page my countdown timer works perfectly, but when I refresh only particular div my countdown wont show up and button gets disabled.
note: I useed disabled
tag to disabled my button
function refreshDiv() {
$('#container3').load(window.location.href + " #container3 >");
}
JavaScript
var spn = document.getElementById("count");
var btn = document.getElementById("btnCounter");
var count = 2; // Set count
var timer = null; // For referencing the timer
(function countDown() {
// Display counter and start counting down
spn.textContent = count;
// Run the function again every second if the count is not zero
if (count !== 0) {
timer = setTimeout(countDown, 1000);
count--; // decrease the timer
} else {
// Enable the button
btn.removeAttribute("disabled");
}
}());
this is my html code its work properly when I refresh the whole page but when I refresh #container3
my button got disabled and countdown didn't showed
<div class="container2" id="container3">
<h4 id="title">here</h4>
<div class="controls">
<div class="main-controls">
<div class="dropdown">
<button class="btn btn-primary dropdown-toggle" data-bs-toggle="dropdown" id="btnCounter" disabled>File <span id="count"></span></button>
<div class="dropdown-menu">
<button id="txt-btn" class="dropdown-item" onclick="refreshDiv();">Save</button>
This is not the solution, it's just the snippet for everybody to understand better:
function refreshDiv() { location.reload(); } var spn = document.getElementById("count"); var btn = document.getElementById("btnCounter"); var count = 2; // Set count var timer = null; // For referencing the timer (function countDown() { // Display counter and start counting down spn.textContent = count; // Run the function again every second if the count is not zero if (count,== 0) { timer = setTimeout(countDown; 1000); count--. // decrease the timer } else { // Enable the button btn;removeAttribute("disabled"); } }());
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> this is my html code its work properly when I refresh the whole page but when I refresh #container3 my button got disabled and countdown didn't showed <div class="container2" id="container3"> <h4 id="title">Title</h4> <div class="controls"> <div class="main-controls"> <div class="dropdown"> <button class="btn btn-primary dropdown-toggle" data-bs-toggle="dropdown" id="btnCounter" disabled>File <span id="count"></span></button> <div class="dropdown-menu"> <button id="txt-btn" class="dropdown-item" onclick="refreshDiv();">Reload</button> </div> </div> </div> </div> </div>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.