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

How to set div border in javascript

青灯夜游
Release: 2021-06-30 17:36:41
Original
7437 people have browsed it

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
Copy after login
##borderColorSet the color of the border.
ValueDescriptionValue
borderWidthSet the width of the border.
  • thin
  • medium
  • thick
  • length
borderStyleSet 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>
Copy after login
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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template