The short answer is no. A slightly longer and more hacky answer: create a function with a one-letter long name that takes the element identifier and returns getElementById on it, and then wrap this in your jQuery $()
, for example:
function i(id) { if (document.getElementById(id)) return document.getElementById(id); else return ""; }
Then:
$(i(id)).doWhatever();
But honestly, think about it:
$("#" + id) 12345678 $(i(id)) 12345
These are three characters. Is it worth it? Are these three characters really that important to you? You already save a lot without using document.getElementById (id) (27 characters).
source share