+ 1

How do we change the border style using java script of a div element written in HTML

27th Apr 2021, 8:44 AM
mustafa raza
mustafa raza - avatar
7 Respostas
+ 5
//Select your element using any selector function (querySelector, getElementById, etc): let element = document.querySelector(".elem") //And then change border style: element.style.border = "1px solid #F00"; https://code.sololearn.com/WKZSK0LUsr7O/?ref=app
27th Apr 2021, 8:48 AM
Artem 🇺🇦
Artem 🇺🇦 - avatar
+ 5
mustafa raza you can just give an onclick to the div element, create the function, and in this function you can put the js code, where it changes the border. :)
27th Apr 2021, 9:27 AM
Matthew
Matthew - avatar
+ 4
Hello mustafa raza, You can get the elements (using document.querySelector or document.getElementById, ....), and using the '.style' and you can write your css code there. If you want to change the border, for example, you can use '.style.border =... ', and so you can access to its style, using css properties etc. :)
27th Apr 2021, 8:49 AM
Matthew
Matthew - avatar
+ 2
document.querySelector("div").borderStyle="groove";
27th Apr 2021, 8:49 AM
Abhay
Abhay - avatar
+ 2
mustafa raza Please don't mark your own answer as the best because in this case it doesn't answer the question.
27th Apr 2021, 9:30 AM
Artem 🇺🇦
Artem 🇺🇦 - avatar
+ 1
Thank you all of you But what if i want to change border style when click on div element area.
27th Apr 2021, 9:17 AM
mustafa raza
mustafa raza - avatar
0
Artem I did't know that tick is used for best answer i clicked it because i want my question on top so that i can get answer quickly.
27th Apr 2021, 9:32 AM
mustafa raza
mustafa raza - avatar