You forgot to define the type of measure in 'borderRadius'
. You may declare 'px'
in front of the amount you will declare.
(Now that I went to see the @Andrewribeiro remark (I didn’t notice much HTML), so I edited the answer code. document.getElementsByTagName
, this method returns an object (similar to the array), HTMLCollection
, of HTML elements containing 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';
Better explanation for this 0
between the square brackets
Basically, square brackets are a way to index an object computationally. Example:
box['style']
is the same as
box.style
.
The point .
and the clasps [...]
allow you to index objects with a specific value, this value returns an object property, or undefined
. So 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
Therefore you cannot index values of type undefined
or null
. You can only index numbers, etc... because they are instance of Object
.
And for more information, what document.getElementsByTagName
returns is not exactly an array, is a given object, but it may not include methods that Array
has in Javascript (type forEach
, push
, etc...), but you can contact him for a Array
yes. I am not stating that the object will not include these methods, as one of its instances may include a similar method in prototype
.
Gosh, I’m missing things too simple. Obg for help!
– Victor
I could only read your question now.... But it is already well answered!
– Allan Andrade