how to select an element by class in JavaScript with getElementsByClassName and set its width without jquery
getElementsByClassName('classname')
does not work
you probably need to use it before the dom has loaded?
as I understand it, but then there is a chance that the element does not exist yet,
whereas if it has already loaded, you can perfectly well use jquery
but if you want to do it in pure JavaScript
then you can do it like this
var elems = document.getElementsByClassName('myclassname'); //getElementById("myid");
for (var i = 0; i
{
elems[i].style.width = 1000+ 'px';
}
Comments