createAttribute()
Обновлено: 16.03.2023
Визначення та використання
Метод createAttribute()створює атрибут і повертає атрибут як об’єкт Attr.
Альтернатива:
Простіше використовувати метод setAttribute() .
Приклади
// Create a class attribute:
const att = document.createAttribute("class");
// Set the value of the class attribute:
att.value = "democlass";
// Add the class attribute to the first h1:
const h1 = document.getElementsByTagName("H1")[0];
h1.setAttributeNode(att);Синтаксис
document.createAttribute(name)
Параметри
| Parameter | Description | 
| name | Required. The name of the attribute to create. | 
Повернене значення
| Тип | опис | 
| Вузол | Створений вузол атрибута. |