หากต้องการกำหนดความกว้าง สไตล์ และสีของเส้นขอบในการประกาศเพียงครั้งเดียว ให้ใช้คุณสมบัติเส้นขอบใน JavaScript
ตัวอย่าง
คุณสามารถลองเรียกใช้โค้ดต่อไปนี้เพื่อเรียนรู้วิธีตั้งค่าเส้นขอบใน JavaScript -
<!DOCTYPE html>
<html>
<body>
<button onclick="display()">Set border</button>
<div id="box">
<p>Demo Text</p>
<p>Demo Text</p>
</div>
<script>
function display() {
document.getElementById("box").style.border = "thick dashed #000000";
}
</script>
</body>
</html>