I was busy making a JavaScript code that allows me to make GUI page elements to have custom context menus, when I thought about checking to see if an element exists in order to make a context menu for it.
function element_exists(el){
var tagName=el.tagName;
var exists=0;
for(var a=0;a<document.getElementsByTagName(tagName).length;a++){
if(document.getElementsByTagName(tagName)[a]==el){
exists=1;
}
}
return exists;
}
In this code, I pass a reference to a DOM element object (which is stored from earlier). Let's say that it was stored, but since then I removed the element itself from the document.
I'm using Chrome Canary, and even if I edit the page through the console and make a new element with the exact same tag name and ID, it returns false. Would it return true if it had the same innerText and innerHTML?
If not, is this a standard in all web browsers (old and new)? Just curious because I could eliminate some unnecessary code if they're all unique.