Advertisement
artemsemkin

Rhye HTML5 Template #1

May 10th, 2021
983
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function syncAttributes($sourceElement, $targetElement) {
  2.  
  3.   if ($sourceElement.length === 1 && $targetElement.length === 1) {
  4.  
  5.     $targetElement.attr($sourceElement.getAllAttributes());
  6.  
  7.   } else if ($sourceElement.length > 1 && $targetElement.length > 1 && $sourceElement.length === $targetElement.length) {
  8.  
  9.     $.each($targetElement, function (index) {
  10.       const
  11.         $current = $(this),
  12.         sourceAttributes = $sourceElement.eq(index).getAllAttributes();
  13.  
  14.       if ($.isEmptyObject(sourceAttributes)) {
  15.         [...this.attributes].forEach(attr => this.removeAttribute(attr.name));
  16.       } else {
  17.         $current.attr(sourceAttributes);
  18.       }
  19.     });
  20.  
  21.   }
  22.  
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement