kael.shipman Posted January 24, 2010 Share Posted January 24, 2010 Hi everyone, Does anyone know if there's an low-level, readonly object ID that can be accessed in javascript for any and all objects across the board? It seems to me that all objects - be it an Array, Object, Image, or from the entire arsenal of HTML elements - should already have an ID that javascript uses to organize them internally. My problem is that I want to uniquely identify HTML objects without having to do a check/write-if-not-exists sequence on the ID attribute of the element. This doesn't apply to any code specifically, but here's an idea: Here, we're putting all of the original text of all the divs on the page - some of which may have html ids but most of which won't - into a hash with the div object's fundamental object id as the key and the text as the value. Then, even if the html id attribute is changed for some reason, that div will always be associated with the text that was cataloged on the pageload. Remember, this doesn't have any practical application, but is a clear example of what I want. window.onload = function() { window.allDivs = {} var docDivs = document.getElementsByTagName('div'); var uniqueId; for(var i = 0; i < docDivs.length; i++) { uniqueID = docDivs[i].lowLevelObjectId; //Note that this is not the simple html ID attribute, since most divs won't have that attribute set window.allDivs[uniqueID] = docDivs[i].innerHTML; } } //Now, assume that people can change the content of whatever div, //so maybe they've changed the content and want to see what was in it originally. //Maybe double-clicking the div calls viewHistory, sending the HTMLDivObject itself as the argument function viewHistory(thisDiv) { history = window.allDivs[thisDiv.lowLevelObjectId]; alert(history); } Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.