Advertisement
adilmchoudhury

Code to limit number of attribute in vendor dashboard

Nov 21st, 2023
1,896
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
jQuery 1.08 KB | None | 0 0
  1. jQuery(document).ready(function($) {
  2.     function checkAttributeLimit() {
  3.         // Select only visible LI elements within the UL
  4.         var visibleAttributeCount = $('.dokan-attribute-option-list > li:visible').length;
  5.  
  6.         if (visibleAttributeCount >= 2) {
  7.             $('.add_new_attribute').hide();
  8.             $('.cant_add_new').show();
  9.         } else {
  10.             $('.add_new_attribute').show();
  11.             $('.cant_add_new').hide();
  12.         }
  13.     }
  14.  
  15.     // Initial check
  16.     checkAttributeLimit();
  17.  
  18.     // Create a Mutation Observer instance
  19.     var observer = new MutationObserver(function(mutations) {
  20.         mutations.forEach(function(mutation) {
  21.             if (mutation.type === 'attributes' && mutation.attributeName === 'style') {
  22.                 checkAttributeLimit();
  23.             }
  24.         });
  25.     });
  26.  
  27.     // Observer configuration
  28.     var config = { attributes: true, childList: false, subtree: true };
  29.  
  30.     // Start observing the target element
  31.     var target = $('.dokan-attribute-option-list')[0];
  32.     observer.observe(target, config);
  33. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement