I have a question regarding DOM selectors.
Is there a difference in performance between the following two code blocks:
First Code Block:
if (document.getElementById("post-dropdown-menu-" + postID) && document.getElementById("post-dropdown-menu-" + postID).style.display != "none") {
document.getElementById("post-dropdown-menu-" + postID).fadeOut(200);
return false;
}
Second Code Block:
var neededElement = document.getElementById("post-dropdown-menu-" + postID);
if (neededElement && neededElement.style.display != "none") {
neededElement.fadeOut(200);
return false;
}
I am curious to know if browsers or JavaScript will reprocess the DOM selection if an element is already being used within a function.