Home  >  Article  >  Web Front-end  >  How to set div border in javascript

How to set div border in javascript

青灯夜游
青灯夜游Original
2021-06-30 17:19:247360browse

How to set the div border in javascript: first use "document.getElementById("ID value")" to get the specified div tag object; then use the "object.style.border="border width style color"" statement to set div border.

How to set div border in javascript

The operating environment of this tutorial: windows7 system, javascript version 1.8.5, Dell G3 computer.

Steps to set div border in javascript:

  • Get div element object

  • Use Style object The border property sets the border

The border property sets all border properties in one statement.

Syntax:

Object.style.border=borderWidth borderStyle borderColor
##borderColorSet the color of the border.
Value Description Value
borderWidth Set the width of the border.
  • thin
  • medium
  • thick
  • length
borderStyle Set the style of the border.
  • none
  • hidden
  • dotted
  • dashed
  • solid
  • double
  • groove
  • ridge
  • inset
  • outset
    color-name
  • color-rgb
  • color-hex
  • transparent
Example:

<!DOCTYPE html>
<html>
<head>
<style type="text/css">
div{ 
padding: 10px;
margin: 10px;
}
</style>
<script type="text/javascript">
function changeBorder()
{
document.getElementById("div1").style.border="thin dotted #FF0000";
}
</script>
</head>
<body>
<div id="div1">div元素,测试文本</div><br /><br />
<input type="button" onclick="changeBorder()" value="设置div边框" />
</body>
</html>

Rendering:

How to set div border in javascript##[Related recommendations:

javascript learning tutorial

The above is the detailed content of How to set div border in javascript. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn