How to get text back when i unselect the checkbox?

  checkbox, dynamic, javascript, onclick, show
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <div><span class="span" id="span">$40</span></div>
    <input type="checkbox" id="tax_type" name="tax_type" onclick="calc();" />
    <script>
    function calc() {
       var checkBox = document.getElementById("tax_type");
       var amount = document.getElementById("span");
        const ac=document.getElementById("span");
      
 if (checkBox.checked == true){
   amount.innerHTML= "You click";
  } else {
   console.log(ac);
  }
    }
    </script>
</body>

</html>

My problem is I append a text when I click checkbox but when I unselect it back then it does not shows the old original one value I have already tried the Inner HTML but it does not work because the prices will be dynamic in my case
Here it is the code , I want if I unselect the checkbox then i get the old one $40 back, I don’t want to append it by inner HTML="$40" because it will be dynamic and the prices will be different in all cases . someone would solve it?

Source: Ask Javascript Questions

LEAVE A COMMENT