SoFunction
Updated on 2025-03-03

JS method to manipulate HTML custom attributes

This article describes how JS operates HTML custom attributes. Share it for your reference. The details are as follows:

The HTML code is as follows (where displayName is a custom property):

Copy the codeThe code is as follows:
<input type="text" displayName="123456" />

Get custom attribute values:

Copy the codeThe code is as follows:
("txtBox").getAttribute("displayName");
("txtInput").attributes["displayName"].nodeValue

Set custom attribute values:

Copy the codeThe code is as follows:
("displayName ","123456");
("txtInput").attributes["displayName"].nodeValue = "123456"

I hope this article will be helpful to everyone's JavaScript programming.