javascript - Change div's width by a value in JS -
how change div
's width value, this:
somediv.style.width += "100px";
it works when want set value (i.e. width = "100px"
) problem +=
operator.
this work vanilla javascript solution (since didn't mention jquery):
var somediv = document.getelementbyid("somediv"); var w = 0; if (typeof somediv.clip !== "undefined") { w = somediv.clip.width; } else { if (somediv.style.pixelwidth) { w = somediv.style.pixelwidth; } else { w = somediv.offsetwidth; } } somediv.style.width = (w + 100) + "px";
Comments
Post a Comment