คุณสมบัติ HTML DOM borderRight ใช้เป็นชวเลขสำหรับรับหรือตั้งค่าคุณสมบัติขอบขวาสำหรับองค์ประกอบ คุณสมบัติ borderRight ประกอบด้วย border-Right-width, border-Right-style, border-Right-color
ต่อไปนี้เป็นไวยากรณ์สำหรับ −
การตั้งค่าคุณสมบัติ borderRight:
object.style.borderRight = "width style color|initial|inherit"
อธิบายคุณสมบัติข้างต้นดังนี้ −
| พารามิเตอร์ | คำอธิบาย |
|---|---|
| ความกว้าง | สำหรับการตั้งค่าความกว้างขอบด้านขวา |
| สไตล์ | สำหรับการตั้งค่าลักษณะเส้นขอบด้านขวา |
| สี | สำหรับการตั้งค่าสีขอบขวา |
| เริ่มต้น | สำหรับการตั้งค่าคุณสมบัตินี้เป็นค่าเริ่มต้น |
| สืบทอด | การสืบทอดค่าคุณสมบัติหลัก |
มาดูตัวอย่างคุณสมบัติ borderRight กัน −
ตัวอย่าง
<!DOCTYPE html>
<html>
<head>
<style>
#P1 {
border-Right: 4px solid magenta;
font-size: 1.5rem;
}
</style>
<script>
function changeBorderRight(){
document.getElementById("P1").style.borderRight="9px dashed red";
document.getElementById("Sample").innerHTML="The Right border for the paragraph element is now";
}
</script>
</head>
<body>
<p id="P1">This is some sample text inside the paragraph. Here is another line of this sample text</p>
<p>Change the above paragraph Right border properties by clicking the below button</p>
<button onclick="changeBorderRight()">Change Border Right</button>
<p id="Sample"></p>
</body>
</html> ผลลัพธ์

เมื่อคลิกปุ่ม "เปลี่ยนขอบด้านขวา" -

ในตัวอย่างข้างต้น −
ขั้นแรกเราได้สร้างย่อหน้าที่มีรหัส “P1” ที่มีข้อความอยู่ภายในและใช้รูปแบบ css ที่เกี่ยวข้อง
#P1 {
border-Right: 4px solid magenta;
font-size: 1.5rem;
}
<p id="P1">This is some sample text inside the paragraph. Here is another line of this sample text</p> จากนั้น เราได้สร้างปุ่ม “เปลี่ยนขอบด้านขวา” ที่จะเรียกใช้ฟังก์ชัน changeBorderRight() เมื่อผู้ใช้คลิก
pre class="result notranslate"> <button onclick="changeBorderRight()">Change Border Right</button>
ฟังก์ชัน changeBorderRight() รับคุณสมบัติสไตล์ borderRight ขององค์ประกอบย่อหน้าที่มีรหัส “P1” โดยใช้เมธอด getElementById() และเปลี่ยนค่าคุณสมบัติเป็น '9px dashed red' ข้อความที่ระบุการเปลี่ยนแปลงนี้จะแสดงในย่อหน้าที่มีรหัส “ตัวอย่าง” โดยใช้คุณสมบัติ innerHTML
function changeBorderRight(){
document.getElementById("P1").style.borderRight="9px dashed red";
document.getElementById("Sample").innerHTML="The right border for the paragraph element is now ";
}