English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

دليل أساسيات JavaScript

أغراض JavaScript

وظائف JavaScript

JS HTML DOM

BOM المتصفح JS

دليل أساسيات AJAX

دليل JavaScript

JS DOM Change Element Attributes

يسمح HTML DOM لـ JavaScript بجمع وتغيير خصائص عناصر HTML.

الحصول على قيمة الخاصية للعنصر

getAttribute()الطريقة المستخدمة للحصول على القيمة الحالية للخصائص المحددة للعنصر.

في المثال التالي يتم الحصول على عناصر المرسلhrefوالاسمقيمة الخاصية:

هذا التعريف هو link = document.getElementById("demo");
هذا التعريف هو href = link.getAttribute("href");
var title = link.getAttribute("title");
Test Look at‹/›

Set attributes on the element

setAttribute()The method is used to set the value of the attribute on the specified element.

If the attribute already exists, the value will be updated; otherwise, a new attribute with the specified name and value will be added.

This example willhrefThe value of the attribute is set to the anchor element:

var x = document.getElementsByTagName("a")[0];
x.setAttribute("href", "https://ar.oldtoolbag.com/css3/");
Test Look at‹/›

Similarly, you can usesetAttribute()The method is used to update or change the value of the existing attribute on the HTML element.

document.getElementsByTagName("input")[0].setAttribute("type", "text");
Test Look at‹/›

Remove attributes from the element

removeAttribute()The method is used to remove attributes from the specified element.

This example removes the anchor elementhrefProperty:

document.getElementsByTagName("a")[0].removeAttribute("href");
Test Look at‹/›