I am using the following function to simplify the use of getElementById:
function elm(obj){
return document.getElementById(obj);
}
//Usage: elm("id").innerHTML = "hello";
My Questions:
- Is it recommended to use it?
- Are there better ways of achieving this?
There is nothing wrong with your function.
The only problem is that if you are like one of the many people that use a Javascript framework to help with the really annoying stuff like events or AJAX then it is probably more idiomatic to instead use whatever function your library already provides to select DOM elements.