Categories
JavaScript Answers

How to change textbox border color using JavaScript?

Spread the love

Sometimes, we want to change textbox border color using JavaScript.

In this article, we’ll look at how to change textbox border color using JavaScript.

How to change textbox border color using JavaScript?

To change textbox border color using JavaScript, we can set the style.border property of the input to red.

For instance, we write:

<input type="text" />

to add an input.

Then we write:

document.querySelector("input").style.border = "1px solid red";

to select the input with querySelector.

And we set the style.border property of it to '1px solider red' to add a red border to it.

Conclusion

To change textbox border color using JavaScript, we can set the style.border property of the input to red.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *