How to increment one or more counters with JavaScript?

JavascriptWeb DevelopmentFront End Scripts

Use the counterIncrement property to increment counters. You can try to run the following code to increment one or more counters with JavaScript −

Example

Live Demo

<!DOCTYPE html>
<html>
   <head>
      <style>
         h2 {
            counter-increment: section;
         }
         h2:before {
            content: counter(section) " Quiz ";
         }
      </style>
   </head>
   <body>
      <h1>Quizzes</h1>
      <p>Change the counterIncrement</p>
      <h2>Ruby</h2>
      <h2 id="myID">Java</h2>
      <h2>PHP</h2>
      <h2>Perl</h2>
      <button onclick="display()">Update Counter Increment</button>
      <script>
         function display() {
            document.getElementById("myID").style.counterIncrement = "subsection";
         }
      </script>
   </body>
</html>
raja
Published on 27-Feb-2018 16:32:17
Advertisements