Get started with jquery-once CDN

(GPL-2.0 OR MIT) licensed

JQuery-once is a lightweight library that ensures a jQuery plugin is executed only once per element on a webpage.

Tags:
  • jquery
  • jquery-plugin

Stable version

Copied!

How to start using jquery-once CDN


<!DOCTYPE html>
<html>
<head>
  <title>Get started with jquery-once CDN - cdnhub.io</title>
  <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
  <script src="https://cdn.cdnhub.io/jquery-once/2.3.0/jquery.once.min.js"></script>
  <script>
    $(document).ready(function() {
      // First time the function is called, it will execute the jQuery code and store it in the cache
      $.once('myFunction', function() {
        $('button').click(function() {
          alert('Button clicked!');
        });
      });

      // Subsequent calls to myFunction will not execute the jQuery code again
      $.once('myFunction');
    });
  </script>
</head>
<body>
  <button>Click me!</button>
</body>
</html>
Copied!
Copied!
Copied!

All versions