Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function syncAttributes($sourceElement, $targetElement) {
- if ($sourceElement.length === 1 && $targetElement.length === 1) {
- $targetElement.attr($sourceElement.getAllAttributes());
- } else if ($sourceElement.length > 1 && $targetElement.length > 1 && $sourceElement.length === $targetElement.length) {
- $.each($targetElement, function (index) {
- const
- $current = $(this),
- sourceAttributes = $sourceElement.eq(index).getAllAttributes();
- if ($.isEmptyObject(sourceAttributes)) {
- [...this.attributes].forEach(attr => this.removeAttribute(attr.name));
- } else {
- $current.attr(sourceAttributes);
- }
- });
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement