js modify tag attribute value

Get and set attributes
getAttribute
object.getAttribute(attribute)
Note: The getAttribute method does not belong to the document object, it can only be called through the element node object.

setAttribute
object.setAttribute(attribute,value)

例子:
var shopping = document.getElementById("purchases");
shopping.setAttribute("title","a list of goods");


The reference article is quoted from Script House: http://www.jb51.net/article/47040.htm

There is also a W3cschool, as shown in the figure:



The other is from W3cschool:



Guess you like

Origin blog.csdn.net/qq_40829962/article/details/78699027