You forgot to set the measure type to 'borderRadius'
. You can declare 'px'
in front of the value you are declaring.
(Now that I've seen @AndrewRibeiro's remark (I did not notice HTML much), so I edited the response code. document.getElementsByTagName
, this method returns an object (similar to array), HTMLCollection
, of HTML elements which contains a specific class.)
var range = parseFloat(document.getElementsById('range').value);
var box = document.getElementsByTagName('box')[0],
output = document.getElementById('rangeValor');
output.value =
box.style.borderRadius = range + 'px';
Best explanation for this 0
between brackets
Basically, brackets are a way to index an object computed. Example:
box['style']
is the same as
box.style
.
The .
point and the [...]
brackets allow you to index objects with a specific value, this value returns a property of the object, or undefined
. Therefore, the .
point only lets you index an object with a string in front. That is, box.style
, here we index box
with the string style
.
Look at an example:
alert(({ hello: 'blabla' }).hello); // blabla
alert(({ hello: 'blabla' })['hello']); // blabla
alert(({}).hello); // undefined
So you can not index values of type undefined
or null
. You can only index numbers, etc ... because they are Object
instance.
And, for more information, what document.getElementsByTagName
returns is not an exactly array, it is a common object, however it may not include methods that Array
has in JavaScript (type forEach
, push
, etc ...), but you can convete it to Array
yes. I'm not claiming that the object will not include these methods, since one of its instances might include a similar method in prototype
.