1
I normally research and do not disturb the patience of the members here, but this time I specifically need an example. See:
<!DOCTYPE html>
<html>
<body>
<select id="lista" size="4">
<option value="A">01</option>
<option value="B">02</option>
<option value="C">03</option>
<option value="D">04</option>
<option value="E">05</option>
<option value="F">06</option>
<option value="G">07</option>
<option value="H">08</option>
<option value="I">09</option>
<option value="J">10</option>
<option value="k">11</option>
<option value="L">12</option>
</select>
<button onclick="somar()">Carregar Mais</button>
</body>
<script>
somar = function() {
var A = document.getElementById('lista');
var B = A.getElementsByTagName('option');
var C = B.length;
B.size = C;
}
</script>
</html>
Note that I am starting the element select
sized[size
] of 4 items sample, but, what I want is something dynamic - auto height adjustment of select
according to the amount of option
. That’s why in the role of example I’m trying to go through the item by the method documentgetElementsByTagName('option')
. In my vision, I thought this might be the solution to a increment to define the property size
.
SUMMARY - Find a way to automatically set the property
size
of the HTML element [select
] without human intervention, let the whole task pro "script" adjust to full size. The idea is that it does not present the vertical scroll bar
Pq vc puts the script out of the body?
– Sam
@dvd I read somewhere online an article by a gringo writer in which he released a book on good web practices [Front-end] and tals. In it he said strongly that developers should look to leave the script(s) at the end, after loading all the content of the page itself. Notice when we access some heavy websites out there, tends to be slow and we see status bar always notifying that there are still elements to be downloaded/loaded. That is, the developer has introduced several scripts at the beginning and body of the page. It gives us the feeling that the Browser will crash.
– Diego Henrique
Yes, I’ve read this too, but when it says "at the end", it doesn’t mean after the body, but at the end of it. That’s what I understood. Now you left me in doubt rss. I will search...
– Sam
@So there are other ways to do this. But some scripts require it to be at first depending on the programing as it should see the HTML element to be hit in the DOM. I put that detail in a comment on some questions that I asked around here in the old days. You got more details, I’m going to do a little digging and I’m going to point something out to +.
– Diego Henrique