how to change the border of an element in javascript

To change the border of an element in JavaScript, you can use the style property of the element to set its CSS properties including border. You can access the element either by document.getElementById() or by other DOM traversal methods.

Here's an example of how to change the border of an element with id "myElement" to a solid red border with a width of 2 pixels:

index.tsx
let element = document.getElementById("myElement");
element.style.border = "2px solid red";
92 chars
3 lines

In this code snippet, we get a reference to the element with the id "myElement" using the document.getElementById() method. Then we set its border style property to "2px solid red".

The border property takes three values: width, style, and color. In this example, we set the width to "2px", the style to "solid", and the color to "red".

gistlibby LogSnag