Is there a better way to write the following function?
Having the '#' + div_id just looks wrong to me.
function hide_div(div_id) {
$('#' + div_id).hide();
}
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Short answer: no. Slightly longer and more hackish answer: create a function with a one-letter long name that takes the element’s ID and returns a getElementById on it, then wrap that in your jQuery
$(), like so:Then:
But honestly, think about it:
That’s three characters. Is it worth it? Do those three characters really matter that much to you? You’re already saving a lot by not using document.getElementById(id) (27 characters).