Your code is ok.
One thing I would consider is whether you want to continue calling document.getElementById() (inside a function) if there is a situation where you need to make several changes to the same element. What I'm going to suggest is redundant to show you more parameters, but think that you can pass the Id to your function or pass a link to an element directly or have a function that takes a string or the element refers to it and indicates its type type:
function objStyleById(oId,p,v){ document.getElementById(oId).style[p]=v; } function objStyle(o,p,v) { o.style[p] = v; } function objStyleAuto(o,p,v) { if (typeof o === "string") o = document.getElementById("o"); // else not a string so assume o is element reference o.style[p] = v; } objStyleById('object','property','value'); var myEl = document.getElementById("someElement"); objStyle(myEl,"prop","val"); objStyle(myEl,"prop2","val"); // some other non-style operation on myEl, eg, myEl.className = "something"; myEl.innerHTML = "something"; objStyle(myEl.parentNode,"prop","value"); objStyleAuto('object','property','value'); objStyleAuto(myEl,'property','value');
source share