Guest User

Charitable Button To Click Donation Button Example

a guest
Dec 19th, 2024
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.05 KB | None | 0 0
  1. function add_custom_footer_script() {
  2.     ?>
  3.     <script type="text/javascript">
  4.         document.addEventListener('DOMContentLoaded', function() {
  5.             // Find the first 'ol.campaign-loop li a.button'
  6.             var targetButton = document.querySelector(‘a.button.charitable-button.donate-button');
  7.  
  8.             // Get all 'a' elements with class "artificial-button"
  9.             var artificialButtons = document.querySelectorAll('a.artificial-button');
  10.  
  11.             // Add a click event listener to each artificial button
  12.             artificialButtons.forEach(function(artificialButton) {
  13.                 artificialButton.addEventListener('click', function(event) {
  14.                     event.preventDefault();  // Prevent the default behavior of the artificial button
  15.                     if (targetButton) {
  16.                         targetButton.click();  // Simulate a click on the actual button
  17.                     }
  18.                 });
  19.             });
  20.         });
  21.     </script>
  22.     <?php
  23. }
  24. add_action('wp_footer', 'add_custom_footer_script');
Advertisement
Add Comment
Please, Sign In to add comment