Hướng dẫn remove all attributes javascript - loại bỏ tất cả các thuộc tính javascript

Một lý do rất chính đáng để làm điều này cho các thẻ cụ thể là để làm sạch nội dung kế thừa và cũng thực thi các tiêu chuẩn.

Ví dụ, giả sử, bạn muốn loại bỏ các thuộc tính cũ hoặc hạn chế thiệt hại do các thuộc tính thẻ phông chữ gây ra bằng cách tước chúng.

Tôi đã thử một số phương pháp để đạt được điều này và không có, bao gồm cả ví dụ trên, hoạt động như mong muốn.

Ví dụ 1: Thay thế tất cả các thẻ phông chữ bằng nội dung văn bản chứa. Đây sẽ là giải pháp hoàn hảo nhưng kể từ v1.6.2 đã ngừng hoạt động. :(

$('#content font').each(function(i) {
   $(this).replaceWith($(this).text());
});

Ví dụ 2: Dải tất cả các thuộc tính từ thẻ có tên - ví dụ: NÉT CHỮ. Một lần nữa, điều này không hoạt động nhưng chắc chắn rằng nó đã từng hoạt động một lần vào phiên bản jQuery trước đó.

$("font").each(function() {
 // First copy the attributes to remove.
 var attributes = $.map(this.attributes, function(item) {
   return item.name;
 });     
 // Now remove the attributes
 var font = $(this);
 $.each(attributes, function(i, item) {
   $("font").removeAttr(item);
 });
});

Mong muốn 1.7 hứa hẹn sẽ bao gồm một phương thức để xóa nhiều thuộc tính theo tên.

Ngày 8 tháng 11 năm 2021 - 1 phút đọc

Hàm JavaScript này sẽ chấp nhận một phần tử HTML đã cho và xóa tất cả các thuộc tính của nó:

const removeAttributes = (element) => {
    while (element.attributes.length > 0) {
        element.removeAttribute(element.attributes[0].name);
    }
};

Nếu bạn không muốn sử dụng vòng lặp while, thì đây là hàm removeAttributes thay thế:

const removeAttributes = (element) => {
    for (let i = 0; i < element.attributes.length; i++) {
        element.removeAttribute(element.attributes[i].name);
    }
};

Bất kể biến thể nào của hàm removeAttributes bạn đã chọn, đây là một số ví dụ sử dụng:

const element = document.getElementById(`example`);

removeAttributes(element);

Trong ví dụ trên, một phần tử có ID example bị tước bỏ tất cả các thuộc tính của nó.

Liên kết đến phần kết luận này

Tôi đã tìm thấy đây là một chức năng cực kỳ đơn giản nhưng cực kỳ hữu ích và tôi hy vọng nó cũng giúp bạn!

Xem thảo luận

Cải thiện bài viết

Lưu bài viết

  • Đọc
  • Bàn luận
  • Xem thảo luận

    Cải thiện bài viết

    Lưu bài viết

    ĐọcremoveAttributeNode() method

    Syntax:

    $.fn.removeAllAttributes = function() {
        return this.each(function() {
            $.each(this.attributes, function() {
                this.ownerElement.removeAttributeNode(this);
            });
        });
    };
    
    $('textarea').removeAllAttributes();

    Bàn luận

    Example:

    Trong bài viết này, chúng ta sẽ xem cách xóa tất cả các thuộc tính của phần tử HTML bằng jQuery.Để xóa tất cả các thuộc tính của các phần tử, chúng tôi sử dụng phương thức removeAtributEnode (). & Nbsp;

    $("font").each(function() {
     // First copy the attributes to remove.
     var attributes = $.map(this.attributes, function(item) {
       return item.name;
     });     
     // Now remove the attributes
     var font = $(this);
     $.each(attributes, function(i, item) {
       $("font").removeAttr(item);
     });
    });
    
    0

    $("font").each(function() {
     // First copy the attributes to remove.
     var attributes = $.map(this.attributes, function(item) {
       return item.name;
     });     
     // Now remove the attributes
     var font = $(this);
     $.each(attributes, function(i, item) {
       $("font").removeAttr(item);
     });
    });
    
    1
    $("font").each(function() {
     // First copy the attributes to remove.
     var attributes = $.map(this.attributes, function(item) {
       return item.name;
     });     
     // Now remove the attributes
     var font = $(this);
     $.each(attributes, function(i, item) {
       $("font").removeAttr(item);
     });
    });
    
    2
    $("font").each(function() {
     // First copy the attributes to remove.
     var attributes = $.map(this.attributes, function(item) {
       return item.name;
     });     
     // Now remove the attributes
     var font = $(this);
     $.each(attributes, function(i, item) {
       $("font").removeAttr(item);
     });
    });
    
    3

    $("font").each(function() {
     // First copy the attributes to remove.
     var attributes = $.map(this.attributes, function(item) {
       return item.name;
     });     
     // Now remove the attributes
     var font = $(this);
     $.each(attributes, function(i, item) {
       $("font").removeAttr(item);
     });
    });
    
    1
    $("font").each(function() {
     // First copy the attributes to remove.
     var attributes = $.map(this.attributes, function(item) {
       return item.name;
     });     
     // Now remove the attributes
     var font = $(this);
     $.each(attributes, function(i, item) {
       $("font").removeAttr(item);
     });
    });
    
    5
    $("font").each(function() {
     // First copy the attributes to remove.
     var attributes = $.map(this.attributes, function(item) {
       return item.name;
     });     
     // Now remove the attributes
     var font = $(this);
     $.each(attributes, function(i, item) {
       $("font").removeAttr(item);
     });
    });
    
    3

    $("font").each(function() {
     // First copy the attributes to remove.
     var attributes = $.map(this.attributes, function(item) {
       return item.name;
     });     
     // Now remove the attributes
     var font = $(this);
     $.each(attributes, function(i, item) {
       $("font").removeAttr(item);
     });
    });
    
    7
    $("font").each(function() {
     // First copy the attributes to remove.
     var attributes = $.map(this.attributes, function(item) {
       return item.name;
     });     
     // Now remove the attributes
     var font = $(this);
     $.each(attributes, function(i, item) {
       $("font").removeAttr(item);
     });
    });
    
    1
    $("font").each(function() {
     // First copy the attributes to remove.
     var attributes = $.map(this.attributes, function(item) {
       return item.name;
     });     
     // Now remove the attributes
     var font = $(this);
     $.each(attributes, function(i, item) {
       $("font").removeAttr(item);
     });
    });
    
    9
    $("font").each(function() {
     // First copy the attributes to remove.
     var attributes = $.map(this.attributes, function(item) {
       return item.name;
     });     
     // Now remove the attributes
     var font = $(this);
     $.each(attributes, function(i, item) {
       $("font").removeAttr(item);
     });
    });
    
    3

    Trong ví dụ dưới đây, chúng tôi đang tạo một phần tử TextArea chứa một số thuộc tính như - hàng, cols, id và tên.Khi chúng tôi áp dụng mã trên trên phần tử Textarea, tất cả các thuộc tính sẽ bị xóa.

    const removeAttributes = (element) => {
        while (element.attributes.length > 0) {
            element.removeAttribute(element.attributes[0].name);
        }
    };
    
    1
    const removeAttributes = (element) => {
        while (element.attributes.length > 0) {
            element.removeAttribute(element.attributes[0].name);
        }
    };
    
    4

    $("font").each(function() {
     // First copy the attributes to remove.
     var attributes = $.map(this.attributes, function(item) {
       return item.name;
     });     
     // Now remove the attributes
     var font = $(this);
     $.each(attributes, function(i, item) {
       $("font").removeAttr(item);
     });
    });
    
    7
    const removeAttributes = (element) => {
        while (element.attributes.length > 0) {
            element.removeAttribute(element.attributes[0].name);
        }
    };
    
    6
    $("font").each(function() {
     // First copy the attributes to remove.
     var attributes = $.map(this.attributes, function(item) {
       return item.name;
     });     
     // Now remove the attributes
     var font = $(this);
     $.each(attributes, function(i, item) {
       $("font").removeAttr(item);
     });
    });
    
    9
    $("font").each(function() {
     // First copy the attributes to remove.
     var attributes = $.map(this.attributes, function(item) {
       return item.name;
     });     
     // Now remove the attributes
     var font = $(this);
     $.each(attributes, function(i, item) {
       $("font").removeAttr(item);
     });
    });
    
    3

    HTML

    $("font").each(function() {
     // First copy the attributes to remove.
     var attributes = $.map(this.attributes, function(item) {
       return item.name;
     });     
     // Now remove the attributes
     var font = $(this);
     $.each(attributes, function(i, item) {
       $("font").removeAttr(item);
     });
    });
    
    7
    const removeAttributes = (element) => {
        while (element.attributes.length > 0) {
            element.removeAttribute(element.attributes[0].name);
        }
    };
    
    6
    const removeAttributes = (element) => {
        for (let i = 0; i < element.attributes.length; i++) {
            element.removeAttribute(element.attributes[i].name);
        }
    };
    
    1
    $("font").each(function() {
     // First copy the attributes to remove.
     var attributes = $.map(this.attributes, function(item) {
       return item.name;
     });     
     // Now remove the attributes
     var font = $(this);
     $.each(attributes, function(i, item) {
       $("font").removeAttr(item);
     });
    });
    
    3

    $("font").each(function() {
     // First copy the attributes to remove.
     var attributes = $.map(this.attributes, function(item) {
       return item.name;
     });     
     // Now remove the attributes
     var font = $(this);
     $.each(attributes, function(i, item) {
       $("font").removeAttr(item);
     });
    });
    
    7
    $("font").each(function() {
     // First copy the attributes to remove.
     var attributes = $.map(this.attributes, function(item) {
       return item.name;
     });     
     // Now remove the attributes
     var font = $(this);
     $.each(attributes, function(i, item) {
       $("font").removeAttr(item);
     });
    });
    
    1
    const element = document.getElementById(`example`);
    
    removeAttributes(element);
    
    0
    $("font").each(function() {
     // First copy the attributes to remove.
     var attributes = $.map(this.attributes, function(item) {
       return item.name;
     });     
     // Now remove the attributes
     var font = $(this);
     $.each(attributes, function(i, item) {
       $("font").removeAttr(item);
     });
    });
    
    3

    const removeAttributes = (element) => {
        while (element.attributes.length > 0) {
            element.removeAttribute(element.attributes[0].name);
        }
    };
    
    1
    const element = document.getElementById(`example`);
    
    removeAttributes(element);
    
    3

    const element = document.getElementById(`example`);
    
    removeAttributes(element);
    
    4
    const element = document.getElementById(`example`);
    
    removeAttributes(element);
    
    5

    const element = document.getElementById(`example`);
    
    removeAttributes(element);
    
    4
    const element = document.getElementById(`example`);
    
    removeAttributes(element);
    
    7

    const removeAttributes = (element) => {
        while (element.attributes.length > 0) {
            element.removeAttribute(element.attributes[0].name);
        }
    };
    
    1
    const element = document.getElementById(`example`);
    
    removeAttributes(element);
    
    9

    $("font").each(function() {
     // First copy the attributes to remove.
     var attributes = $.map(this.attributes, function(item) {
       return item.name;
     });     
     // Now remove the attributes
     var font = $(this);
     $.each(attributes, function(i, item) {
       $("font").removeAttr(item);
     });
    });
    
    7
    const removeAttributes = (element) => {
        while (element.attributes.length > 0) {
            element.removeAttribute(element.attributes[0].name);
        }
    };
    
    6
    const element = document.getElementById(`example`);
    
    removeAttributes(element);
    
    0
    $("font").each(function() {
     // First copy the attributes to remove.
     var attributes = $.map(this.attributes, function(item) {
       return item.name;
     });     
     // Now remove the attributes
     var font = $(this);
     $.each(attributes, function(i, item) {
       $("font").removeAttr(item);
     });
    });
    
    3

    $("font").each(function() {
     // First copy the attributes to remove.
     var attributes = $.map(this.attributes, function(item) {
       return item.name;
     });     
     // Now remove the attributes
     var font = $(this);
     $.each(attributes, function(i, item) {
       $("font").removeAttr(item);
     });
    });
    
    7
    $("font").each(function() {
     // First copy the attributes to remove.
     var attributes = $.map(this.attributes, function(item) {
       return item.name;
     });     
     // Now remove the attributes
     var font = $(this);
     $.each(attributes, function(i, item) {
       $("font").removeAttr(item);
     });
    });
    
    1
    const removeAttributes = (element) => {
        for (let i = 0; i < element.attributes.length; i++) {
            element.removeAttribute(element.attributes[i].name);
        }
    };
    
    1
    $("font").each(function() {
     // First copy the attributes to remove.
     var attributes = $.map(this.attributes, function(item) {
       return item.name;
     });     
     // Now remove the attributes
     var font = $(this);
     $.each(attributes, function(i, item) {
       $("font").removeAttr(item);
     });
    });
    
    3

    const removeAttributes = (element) => {
        while (element.attributes.length > 0) {
            element.removeAttribute(element.attributes[0].name);
        }
    };
    
    1
    $.fn.removeAllAttributes = function() {
        return this.each(function() {
            $.each(this.attributes, function() {
                this.ownerElement.removeAttributeNode(this);
            });
        });
    };
    
    $('textarea').removeAllAttributes();
    9

    const element = document.getElementById(`example`);
    
    removeAttributes(element);
    
    4while1

    while2while3

    while4while5

    while6while7

    while8while9

    while6removeAttributes1

    while4removeAttributes1

    while2removeAttributes5

    while2removeAttributes7

    const element = document.getElementById(`example`);
    
    removeAttributes(element);
    
    4removeAttributes1

    const removeAttributes = (element) => {
        while (element.attributes.length > 0) {
            element.removeAttribute(element.attributes[0].name);
        }
    };
    
    1removeAttributes1

    $("font").each(function() {
     // First copy the attributes to remove.
     var attributes = $.map(this.attributes, function(item) {
       return item.name;
     });     
     // Now remove the attributes
     var font = $(this);
     $.each(attributes, function(i, item) {
       $("font").removeAttr(item);
     });
    });
    
    7
    const removeAttributes = (element) => {
        while (element.attributes.length > 0) {
            element.removeAttribute(element.attributes[0].name);
        }
    };
    
    6
    const removeAttributes = (element) => {
        for (let i = 0; i < element.attributes.length; i++) {
            element.removeAttribute(element.attributes[i].name);
        }
    };
    
    1
    $("font").each(function() {
     // First copy the attributes to remove.
     var attributes = $.map(this.attributes, function(item) {
       return item.name;
     });     
     // Now remove the attributes
     var font = $(this);
     $.each(attributes, function(i, item) {
       $("font").removeAttr(item);
     });
    });
    
    3

    const removeAttributes = (element) => {
        while (element.attributes.length > 0) {
            element.removeAttribute(element.attributes[0].name);
        }
    };
    
    6
    $("font").each(function() {
     // First copy the attributes to remove.
     var attributes = $.map(this.attributes, function(item) {
       return item.name;
     });     
     // Now remove the attributes
     var font = $(this);
     $.each(attributes, function(i, item) {
       $("font").removeAttr(item);
     });
    });
    
    5
    $("font").each(function() {
     // First copy the attributes to remove.
     var attributes = $.map(this.attributes, function(item) {
       return item.name;
     });     
     // Now remove the attributes
     var font = $(this);
     $.each(attributes, function(i, item) {
       $("font").removeAttr(item);
     });
    });
    
    3

    $("font").each(function() {
     // First copy the attributes to remove.
     var attributes = $.map(this.attributes, function(item) {
       return item.name;
     });     
     // Now remove the attributes
     var font = $(this);
     $.each(attributes, function(i, item) {
       $("font").removeAttr(item);
     });
    });
    
    1example0
    $("font").each(function() {
     // First copy the attributes to remove.
     var attributes = $.map(this.attributes, function(item) {
       return item.name;
     });     
     // Now remove the attributes
     var font = $(this);
     $.each(attributes, function(i, item) {
       $("font").removeAttr(item);
     });
    });
    
    3

    $("font").each(function() {
     // First copy the attributes to remove.
     var attributes = $.map(this.attributes, function(item) {
       return item.name;
     });     
     // Now remove the attributes
     var font = $(this);
     $.each(attributes, function(i, item) {
       $("font").removeAttr(item);
     });
    });
    
    7
    $("font").each(function() {
     // First copy the attributes to remove.
     var attributes = $.map(this.attributes, function(item) {
       return item.name;
     });     
     // Now remove the attributes
     var font = $(this);
     $.each(attributes, function(i, item) {
       $("font").removeAttr(item);
     });
    });
    
    1example4
    $("font").each(function() {
     // First copy the attributes to remove.
     var attributes = $.map(this.attributes, function(item) {
       return item.name;
     });     
     // Now remove the attributes
     var font = $(this);
     $.each(attributes, function(i, item) {
       $("font").removeAttr(item);
     });
    });
    
    3

    const removeAttributes = (element) => {
        while (element.attributes.length > 0) {
            element.removeAttribute(element.attributes[0].name);
        }
    };
    
    1
    const removeAttributes = (element) => {
        while (element.attributes.length > 0) {
            element.removeAttribute(element.attributes[0].name);
        }
    };
    
    2

    const element = document.getElementById(`example`);
    
    removeAttributes(element);
    
    4
    $("font").each(function() {
     // First copy the attributes to remove.
     var attributes = $.map(this.attributes, function(item) {
       return item.name;
     });     
     // Now remove the attributes
     var font = $(this);
     $.each(attributes, function(i, item) {
       $("font").removeAttr(item);
     });
    });
    
    04

    const removeAttributes = (element) => {
        while (element.attributes.length > 0) {
            element.removeAttribute(element.attributes[0].name);
        }
    };
    
    1
    const removeAttributes = (element) => {
        while (element.attributes.length > 0) {
            element.removeAttribute(element.attributes[0].name);
        }
    };
    
    6example8
    $("font").each(function() {
     // First copy the attributes to remove.
     var attributes = $.map(this.attributes, function(item) {
       return item.name;
     });     
     // Now remove the attributes
     var font = $(this);
     $.each(attributes, function(i, item) {
       $("font").removeAttr(item);
     });
    });
    
    3

    const removeAttributes = (element) => {
        while (element.attributes.length > 0) {
            element.removeAttribute(element.attributes[0].name);
        }
    };
    
    1
    $("font").each(function() {
     // First copy the attributes to remove.
     var attributes = $.map(this.attributes, function(item) {
       return item.name;
     });     
     // Now remove the attributes
     var font = $(this);
     $.each(attributes, function(i, item) {
       $("font").removeAttr(item);
     });
    });
    
    1
    $("font").each(function() {
     // First copy the attributes to remove.
     var attributes = $.map(this.attributes, function(item) {
       return item.name;
     });     
     // Now remove the attributes
     var font = $(this);
     $.each(attributes, function(i, item) {
       $("font").removeAttr(item);
     });
    });
    
    11
    $("font").each(function() {
     // First copy the attributes to remove.
     var attributes = $.map(this.attributes, function(item) {
       return item.name;
     });     
     // Now remove the attributes
     var font = $(this);
     $.each(attributes, function(i, item) {
       $("font").removeAttr(item);
     });
    });
    
    3

    const element = document.getElementById(`example`);
    
    removeAttributes(element);
    
    4
    const removeAttributes = (element) => {
        while (element.attributes.length > 0) {
            element.removeAttribute(element.attributes[0].name);
        }
    };
    
    2

    const element = document.getElementById(`example`);
    
    removeAttributes(element);
    
    4
    const removeAttributes = (element) => {
        while (element.attributes.length > 0) {
            element.removeAttribute(element.attributes[0].name);
        }
    };
    
    4

    $("font").each(function() {
     // First copy the attributes to remove.
     var attributes = $.map(this.attributes, function(item) {
       return item.name;
     });     
     // Now remove the attributes
     var font = $(this);
     $.each(attributes, function(i, item) {
       $("font").removeAttr(item);
     });
    });
    
    7
    $("font").each(function() {
     // First copy the attributes to remove.
     var attributes = $.map(this.attributes, function(item) {
       return item.name;
     });     
     // Now remove the attributes
     var font = $(this);
     $.each(attributes, function(i, item) {
       $("font").removeAttr(item);
     });
    });
    
    1
    const removeAttributes = (element) => {
        for (let i = 0; i < element.attributes.length; i++) {
            element.removeAttribute(element.attributes[i].name);
        }
    };
    
    1
    const removeAttributes = (element) => {
        for (let i = 0; i < element.attributes.length; i++) {
            element.removeAttribute(element.attributes[i].name);
        }
    };
    
    2
    const removeAttributes = (element) => {
        for (let i = 0; i < element.attributes.length; i++) {
            element.removeAttribute(element.attributes[i].name);
        }
    };
    
    3

    const removeAttributes = (element) => {
        while (element.attributes.length > 0) {
            element.removeAttribute(element.attributes[0].name);
        }
    };
    
    1
    $("font").each(function() {
     // First copy the attributes to remove.
     var attributes = $.map(this.attributes, function(item) {
       return item.name;
     });     
     // Now remove the attributes
     var font = $(this);
     $.each(attributes, function(i, item) {
       $("font").removeAttr(item);
     });
    });
    
    1example8
    const element = document.getElementById(`example`);
    
    removeAttributes(element);
    
    0
    const removeAttributes = (element) => {
        for (let i = 0; i < element.attributes.length; i++) {
            element.removeAttribute(element.attributes[i].name);
        }
    };
    
    3
    $("font").each(function() {
     // First copy the attributes to remove.
     var attributes = $.map(this.attributes, function(item) {
       return item.name;
     });     
     // Now remove the attributes
     var font = $(this);
     $.each(attributes, function(i, item) {
       $("font").removeAttr(item);
     });
    });
    
    01
    $("font").each(function() {
     // First copy the attributes to remove.
     var attributes = $.map(this.attributes, function(item) {
       return item.name;
     });     
     // Now remove the attributes
     var font = $(this);
     $.each(attributes, function(i, item) {
       $("font").removeAttr(item);
     });
    });
    
    3

    const element = document.getElementById(`example`);
    
    removeAttributes(element);
    
    4
    $("font").each(function() {
     // First copy the attributes to remove.
     var attributes = $.map(this.attributes, function(item) {
       return item.name;
     });     
     // Now remove the attributes
     var font = $(this);
     $.each(attributes, function(i, item) {
       $("font").removeAttr(item);
     });
    });
    
    31
    const removeAttributes = (element) => {
        for (let i = 0; i < element.attributes.length; i++) {
            element.removeAttribute(element.attributes[i].name);
        }
    };
    
    3
    $("font").each(function() {
     // First copy the attributes to remove.
     var attributes = $.map(this.attributes, function(item) {
       return item.name;
     });     
     // Now remove the attributes
     var font = $(this);
     $.each(attributes, function(i, item) {
       $("font").removeAttr(item);
     });
    });
    
    33 

    const element = document.getElementById(`example`);
    
    removeAttributes(element);
    
    4
    const element = document.getElementById(`example`);
    
    removeAttributes(element);
    
    0
    const removeAttributes = (element) => {
        for (let i = 0; i < element.attributes.length; i++) {
            element.removeAttribute(element.attributes[i].name);
        }
    };
    
    3
    $("font").each(function() {
     // First copy the attributes to remove.
     var attributes = $.map(this.attributes, function(item) {
       return item.name;
     });     
     // Now remove the attributes
     var font = $(this);
     $.each(attributes, function(i, item) {
       $("font").removeAttr(item);
     });
    });
    
    37
    $("font").each(function() {
     // First copy the attributes to remove.
     var attributes = $.map(this.attributes, function(item) {
       return item.name;
     });     
     // Now remove the attributes
     var font = $(this);
     $.each(attributes, function(i, item) {
       $("font").removeAttr(item);
     });
    });
    
    3

    const removeAttributes = (element) => {
        while (element.attributes.length > 0) {
            element.removeAttribute(element.attributes[0].name);
        }
    };
    
    1
    $("font").each(function() {
     // First copy the attributes to remove.
     var attributes = $.map(this.attributes, function(item) {
       return item.name;
     });     
     // Now remove the attributes
     var font = $(this);
     $.each(attributes, function(i, item) {
       $("font").removeAttr(item);
     });
    });
    
    1
    $("font").each(function() {
     // First copy the attributes to remove.
     var attributes = $.map(this.attributes, function(item) {
       return item.name;
     });     
     // Now remove the attributes
     var font = $(this);
     $.each(attributes, function(i, item) {
       $("font").removeAttr(item);
     });
    });
    
    41
    $("font").each(function() {
     // First copy the attributes to remove.
     var attributes = $.map(this.attributes, function(item) {
       return item.name;
     });     
     // Now remove the attributes
     var font = $(this);
     $.each(attributes, function(i, item) {
       $("font").removeAttr(item);
     });
    });
    
    42
    $("font").each(function() {
     // First copy the attributes to remove.
     var attributes = $.map(this.attributes, function(item) {
       return item.name;
     });     
     // Now remove the attributes
     var font = $(this);
     $.each(attributes, function(i, item) {
       $("font").removeAttr(item);
     });
    });
    
    41
    $("font").each(function() {
     // First copy the attributes to remove.
     var attributes = $.map(this.attributes, function(item) {
       return item.name;
     });     
     // Now remove the attributes
     var font = $(this);
     $.each(attributes, function(i, item) {
       $("font").removeAttr(item);
     });
    });
    
    3

    const removeAttributes = (element) => {
        while (element.attributes.length > 0) {
            element.removeAttribute(element.attributes[0].name);
        }
    };
    
    1
    $("font").each(function() {
     // First copy the attributes to remove.
     var attributes = $.map(this.attributes, function(item) {
       return item.name;
     });     
     // Now remove the attributes
     var font = $(this);
     $.each(attributes, function(i, item) {
       $("font").removeAttr(item);
     });
    });
    
    1
    $("font").each(function() {
     // First copy the attributes to remove.
     var attributes = $.map(this.attributes, function(item) {
       return item.name;
     });     
     // Now remove the attributes
     var font = $(this);
     $.each(attributes, function(i, item) {
       $("font").removeAttr(item);
     });
    });
    
    47
    $("font").each(function() {
     // First copy the attributes to remove.
     var attributes = $.map(this.attributes, function(item) {
       return item.name;
     });     
     // Now remove the attributes
     var font = $(this);
     $.each(attributes, function(i, item) {
       $("font").removeAttr(item);
     });
    });
    
    48
    const removeAttributes = (element) => {
        for (let i = 0; i < element.attributes.length; i++) {
            element.removeAttribute(element.attributes[i].name);
        }
    };
    
    3
    $("font").each(function() {
     // First copy the attributes to remove.
     var attributes = $.map(this.attributes, function(item) {
       return item.name;
     });     
     // Now remove the attributes
     var font = $(this);
     $.each(attributes, function(i, item) {
       $("font").removeAttr(item);
     });
    });
    
    50
    $("font").each(function() {
     // First copy the attributes to remove.
     var attributes = $.map(this.attributes, function(item) {
       return item.name;
     });     
     // Now remove the attributes
     var font = $(this);
     $.each(attributes, function(i, item) {
       $("font").removeAttr(item);
     });
    });
    
    51
    const removeAttributes = (element) => {
        for (let i = 0; i < element.attributes.length; i++) {
            element.removeAttribute(element.attributes[i].name);
        }
    };
    
    3
    $("font").each(function() {
     // First copy the attributes to remove.
     var attributes = $.map(this.attributes, function(item) {
       return item.name;
     });     
     // Now remove the attributes
     var font = $(this);
     $.each(attributes, function(i, item) {
       $("font").removeAttr(item);
     });
    });
    
    53 ________ 127 ________ 33 ________ 156 & nbs

    const element = document.getElementById(`example`);
    
    removeAttributes(element);
    
    4
    $("font").each(function() {
     // First copy the attributes to remove.
     var attributes = $.map(this.attributes, function(item) {
       return item.name;
     });     
     // Now remove the attributes
     var font = $(this);
     $.each(attributes, function(i, item) {
       $("font").removeAttr(item);
     });
    });
    
    58
    const removeAttributes = (element) => {
        for (let i = 0; i < element.attributes.length; i++) {
            element.removeAttribute(element.attributes[i].name);
        }
    };
    
    3
    $("font").each(function() {
     // First copy the attributes to remove.
     var attributes = $.map(this.attributes, function(item) {
       return item.name;
     });     
     // Now remove the attributes
     var font = $(this);
     $.each(attributes, function(i, item) {
       $("font").removeAttr(item);
     });
    });
    
    60
    $("font").each(function() {
     // First copy the attributes to remove.
     var attributes = $.map(this.attributes, function(item) {
       return item.name;
     });     
     // Now remove the attributes
     var font = $(this);
     $.each(attributes, function(i, item) {
       $("font").removeAttr(item);
     });
    });
    
    61

    const removeAttributes = (element) => {
        while (element.attributes.length > 0) {
            element.removeAttribute(element.attributes[0].name);
        }
    };
    
    1
    const removeAttributes = (element) => {
        while (element.attributes.length > 0) {
            element.removeAttribute(element.attributes[0].name);
        }
    };
    
    6
    $("font").each(function() {
     // First copy the attributes to remove.
     var attributes = $.map(this.attributes, function(item) {
       return item.name;
     });     
     // Now remove the attributes
     var font = $(this);
     $.each(attributes, function(i, item) {
       $("font").removeAttr(item);
     });
    });
    
    47
    $("font").each(function() {
     // First copy the attributes to remove.
     var attributes = $.map(this.attributes, function(item) {
       return item.name;
     });     
     // Now remove the attributes
     var font = $(this);
     $.each(attributes, function(i, item) {
       $("font").removeAttr(item);
     });
    });
    
    3

    $("font").each(function() {
     // First copy the attributes to remove.
     var attributes = $.map(this.attributes, function(item) {
       return item.name;
     });     
     // Now remove the attributes
     var font = $(this);
     $.each(attributes, function(i, item) {
       $("font").removeAttr(item);
     });
    });
    
    7
    const removeAttributes = (element) => {
        while (element.attributes.length > 0) {
            element.removeAttribute(element.attributes[0].name);
        }
    };
    
    6example4
    $("font").each(function() {
     // First copy the attributes to remove.
     var attributes = $.map(this.attributes, function(item) {
       return item.name;
     });     
     // Now remove the attributes
     var font = $(this);
     $.each(attributes, function(i, item) {
       $("font").removeAttr(item);
     });
    });
    
    3

    const removeAttributes = (element) => {
        while (element.attributes.length > 0) {
            element.removeAttribute(element.attributes[0].name);
        }
    };
    
    6example0
    $("font").each(function() {
     // First copy the attributes to remove.
     var attributes = $.map(this.attributes, function(item) {
       return item.name;
     });     
     // Now remove the attributes
     var font = $(this);
     $.each(attributes, function(i, item) {
       $("font").removeAttr(item);
     });
    });
    
    3

    const removeAttributes = (element) => {
        while (element.attributes.length > 0) {
            element.removeAttribute(element.attributes[0].name);
        }
    };
    
    6
    $("font").each(function() {
     // First copy the attributes to remove.
     var attributes = $.map(this.attributes, function(item) {
       return item.name;
     });     
     // Now remove the attributes
     var font = $(this);
     $.each(attributes, function(i, item) {
       $("font").removeAttr(item);
     });
    });
    
    2
    $("font").each(function() {
     // First copy the attributes to remove.
     var attributes = $.map(this.attributes, function(item) {
       return item.name;
     });     
     // Now remove the attributes
     var font = $(this);
     $.each(attributes, function(i, item) {
       $("font").removeAttr(item);
     });
    });
    
    3

    Output:

    Hướng dẫn remove all attributes javascript - loại bỏ tất cả các thuộc tính javascript