+ 2

Hello, how can I access the attributes of an element by using Javascript? I tried this without success. Thanks.

https://code.sololearn.com/WN9PaE5v67Ie/?ref=app

12th Feb 2018, 3:08 AM
Alfredo Girón Zúñiga
Alfredo Girón Zúñiga - avatar
5 Respuestas
12th Feb 2018, 3:17 AM
Jonathan Pizarra (JS Challenger)
Jonathan Pizarra (JS Challenger) - avatar
+ 5
Although @Jonathan's way is the preferred method in pure Javascript (IMO) you could also just shorten it to; getComputedStyle(box).width
12th Feb 2018, 4:24 AM
ChaoticDawg
ChaoticDawg - avatar
+ 4
Or you can use jquery. import it first, then $("#id").attr("atrribute")....
12th Feb 2018, 3:19 AM
Meharban Singh
Meharban Singh - avatar
+ 4
The HTMLElement.style property is used to get as well as set the inline style of an element. It can't read external CSS style.  More info pls check https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/style
12th Feb 2018, 5:47 AM
Calviղ
Calviղ - avatar
+ 3
Thanks you all. I used Jonathan's solution.
12th Feb 2018, 6:27 AM
Alfredo Girón Zúñiga
Alfredo Girón Zúñiga - avatar