createAttribute()

Misollar

// 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);
O‘zingiz sinab ko‘ring »
// Create a style attribute: const att = document.createAttribute("style"); // Set the value of the style attribute: att.value = "color:red"; // Add the style attribute to the first h1: const h1 = document.getElementsByTagName("h1")[0]; h1.setAttributeNode(att);
O‘zingiz sinab ko‘ring »

Quyida ko‘proq misollar.


ULASHISH

Tavsif

createAttribute() metodi atribut yaratadi va uni Attr obyekti sifatida qaytaradi.


Sintaksis

document.createAttribute(name)

Parametrlar

Parametr Tavsif
name Majburiy.
Yaratiladigan atribut nomi.

Qaytariladigan qiymat

Tip Tavsif
NodeYaratilgan atribut tuguni.


Ko‘proq misollar

Langar (anchor) elementiga href="www.w3schools.com" atributini qo‘shing:

// Create a href attribute: const att = document.createAttribute("href"); // Set the value of the href attribute: att.value = "https://www.w3schools.com"; // Add the href attribute to an element: element.setAttributeNode(att);
O‘zingiz sinab ko‘ring »

Brauzerlarda qo‘llab-quvvatlash

document.createAttribute() — DOM Level 1 (1998) imkoniyati.

U barcha brauzerlarda to‘liq qo‘llab-quvvatlanadi:

Chrome Edge Firefox Safari Opera IE
Ha Ha Ha Ha Ha 9-11


W3Schools Pathfinder

Yutuqlaringizni kuzating – bu bepul!