![]() |
In this article, we will see how to change the Border of HTML element using JavaSCript. To change the border of an element, first, we select the element, and then use HTML DOM border style property to change the border. The CSS border properties are given below:
Syntax: element.style.borderColor
Example 1: In this following example, the JavaScript code now additionally locates the button element using its ID and uses the addEventListener function to add a click event listener to it. The event listener function’s code is called when the button is pressed, changing the div element’s border style to 3 pixels wide, solid, and green, and also we added a border-radius to round the solid line. To change the border to a new design or color, you may adjust the code inside the event listener function. And we added some style to the button to make it more attractive. HTML
Output: ![]()
Example 2: In the following example there is three div. When the button is clicked javascript is going to execute and change the border styles of each div element also in this example div has different types of border-radius. The border-top, border-right, border-bottom, and border-left properties are used to set different border styles for each side of the border. HTML
Output: ![]()
|
Reffered: https://www.geeksforgeeks.org
JavaScript |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 13 |