JavaScript – Change the Border of HTML Element

To change the border of a HTML Element using JavaScript, get reference to this HTML element, and assign required border value to the element.style.border property.

In the following example, we will change the border of HTML Element with id "myElement" to "2px dotted red", in JavaScript, using element.style.border property.

example.html

ADVERTISEMENT

Conclusion

In this JavaScript Tutorial, we learned how to change the border of a HTML Element using JavaScript.