As Pekka says, it would be easier if you would describe what you want to do. Until then here are two suggestions.
Unless you actually need to express the id as some kind of string you can save the normal DOM reference.
If you do need to express it as a string for some reason, then you'll need to assign a unique id yourself.
var getId = (function () {
var incrementingId = 0;
return function(element) {
if (!element.id) {
element.id = "id_" + incrementingId++;
// Possibly add a check if this ID really is unique
}
return element.id;
};
}());
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…