HTML DOM removeAttributeNode () Method
❮ عنصر العنصرمثال
قم بإزالة عقدة سمة الفئة من عنصر <h1>:
var elmnt = document.getElementsByTagName("H1")[0]; // Get the first <h1> element in the document
var attr = elmnt.getAttributeNode("class"); // Get the class attribute node from <h1>
elmnt.removeAttributeNode(attr); // Remove the class attribute node from <h1>
التعريف والاستخدام
أسلوب removeAttributeNode () يزيل السمة المحددة من عنصر ، ويعيد السمة التي تمت إزالتها ، ككائن Attr Node .
يتمثل الاختلاف بين هذه الطريقة وطريقة removeAttribute () في أن طريقة removeAttribute () تزيل السمة بالاسم المحدد ، بينما تزيل هذه الطريقة كائن Attr المحدد . وستكون النتيجة نفسها. أيضًا ، لا تحتوي طريقة removeAttribute () على قيمة إرجاع ، بينما تُرجع هذه الطريقة السمة التي تمت إزالتها ، ككائن Attr.
تلميح: استخدم طريقة getAttributeNode () لإرجاع عقدة سمة لعنصر.
نصيحة: استخدم طريقة setAttributeNode () لإضافة عقدة سمة إلى عنصر.
دعم المتصفح
Method | |||||
---|---|---|---|---|---|
removeAttributeNode() | Yes | Yes | Yes | Yes | Yes |
بناء الجملة
element.removeAttributeNode(attributenode)
قيمه المعامل
Parameter | Type | Description |
---|---|---|
attributenode | Attr object | Required. The attribute node you want to remove |
تفاصيل تقنية
قيمة الإرجاع: | كائن Attr ، يمثل عقدة السمة التي تمت إزالتها |
---|---|
إصدار DOM | كائن عنصر المستوى 1 الأساسي |
مزيد من الأمثلة
مثال
قم بإزالة عقدة سمة href من عنصر <a>:
var elmnt = document.getElementById("myAnchor"); // Get the <a> element with id="myAnchor"
var attr = elmnt.getAttributeNode("href"); // Get the href attribute node from <a>
elmnt.removeAttributeNode(attr); // Remove the href attribute node from <a>
الصفحات ذات الصلة
دروس HTML: سمات HTML
مرجع HTML DOM: كائن سمة HTML DOM
مرجع DOM HTML: طريقة removeAttribute ()
مرجع HTML DOM: أسلوب getAttributeNode ()
مرجع HTML DOM: طريقة setAttributeNode ()
❮ عنصر العنصر