How to change element attributes in JavaScript: 1. Use the "element object.attribute = new value" statement; 2. Use the "element object.setAttribute('attribute','attribute value')" statement.
The operating environment of this tutorial: windows7 system, javascript version 1.8.5, Dell G3 computer.
JavaScript to change element attributes
1. Use the "element object.attribute = new value
" statement
Example: Modified the value of the src attribute of theelement:
Method 2: Use the setAttribute() function
## The #setAttribute() method adds the specified attribute and assigns it the specified value. If this specified property already exists, the value is only set/changed. Syntax:Element object.setAttribute('attribute','attribute value');
hello欢迎来到PHP中文网!
javascript advanced tutorial]
The above is the detailed content of How to change element attributes in JavaScript. For more information, please follow other related articles on the PHP Chinese website!