HTML DOM Öğesi getAttribute()
❮ Öğe NesnesiÖrnek
Bir öğenin sınıf özniteliğinin değerini alın:
let value = document.getElementById("myId").getAttribute("class");
Aşağıda daha fazla örnek.
Tanım ve Kullanım
Yöntem getAttribute()
, bir öğenin özniteliğinin değerini döndürür.
öğretici
Ayrıca bakınız:
Sözdizimi
element.getAttribute(attributename)
Parametre Değerleri
Parameter | Type | Description |
---|---|---|
attributename | String | Required. The name of the attribute you want to get the value from |
Teknik detaylar
Geri dönüş değeri: | Belirtilen özniteliğin değerini temsil eden bir Dize. Not: Öznitelik yoksa, dönüş değeri null veya boş bir dizedir ("") |
---|---|
DOM Sürümü | Çekirdek Düzey 1 Öğe Nesnesi |
Daha fazla örnek
Örnek
Bir <a> öğesinin hedef niteliğinin değerini alın:
var x = document.getElementById("myAnchor").getAttribute("target");
Örnek
Bir <button> öğesinin onclick olay özniteliğinin değerini alın:
var x = document.getElementById("myBtn").getAttribute("onclick");
Tarayıcı Desteği
element.getAttribute
bir DOM Düzey 1 (1998) özelliğidir.
Tüm tarayıcılarda tam olarak desteklenir:
Chrome | IE | Edge | Firefox | Safari | Opera |
Yes | 9-11 | Yes | Yes | Yes | Yes |
❮ Öğe Nesnesi