171
rated 0 times
[
176]
[
5]
/ answers: 1 / hits: 16545
/ 9 Years ago, wed, august 12, 2015, 12:00:00
In particular why does document.getElementsById work here
<div id=move>add padding</div>
<button type=button onclick=movefun()>pad</button>
<script>
function movefun() {
document.getElementById(move).style.paddingLeft = 50px;
}
</script>
but document.getElementsByClassName does not work
<div class=move>add padding</div>
<button type=button onclick=movefun()>Set left padding</button>
<script>
function movefun() {
document.getElementsByClassName(move).style.paddingLeft = 50px;
}
</script>
I have left out the common things like the html and body tag to cut down on code length.
More From » jquery