Javascript DOM CSS Style outline Property set

Introduction

Change the width, style and color of the outline of a <div> element:

document.getElementById("myDiv").style.outline = "5px dotted green";

View in separate window

<!DOCTYPE html>
<html>
<head>
<style>
#myDiv {/*from   w  w w  . jav  a  2s  .  c o m*/
  border: 3px solid red;
  outline: 3px solid blue;
}
</style>
</head>
<body>

<div id="myDiv">This is a div.</div>
<br>
<button type="button" onclick="myFunction()">Change outline</button>

<script>
function myFunction() {
  document.getElementById("myDiv").style.outline = "5px dotted green";
}
</script>

</body>
</html>



PreviousNext

Related