How to add a border to an element in JavaScript: 1. Use the statement "Element object.style.border="width value style value color value""; 2. Use "Element object.style.cssText="border" :Width value style value color value "" statement.
The operating environment of this tutorial: windows7 system, javascript version 1.8.5, Dell G3 computer.
Method 1: Use HTML DOM border attribute
Syntax: Object.style.border=borderWidth borderStyle borderColor
Example:
单击按钮给div元素添加边框
div元素
Rendering:
##2. Use cssText attribute
The essence of cssText is to set the style attribute value of HTML elements. Syntax:Object.style.cssText="Attribute name: attribute value";
单击按钮给div元素添加边框
div元素
javascript advanced tutorial]
The above is the detailed content of How to add borders to elements in javascript. For more information, please follow other related articles on the PHP Chinese website!