xxxxxxxxxx
//in the constructor of your custom element
constructor(){
//you can use the document object to escape sandboxing and set global variables
//check to see if your variable exists
if(document.customElementID==undefined){
//if it doesn't exist, set it to 0
document.customElementID = 0;
}else{
//if it does exist, add 1
document.customElementID++;
}
/*
this is a one line version of the above if else statement
document.customElementID = (document.customElementID==undefined?0:document.customElementID+1);
*/
//customElementID tracks how many of this element are on the webpage
//this's ID = the current count
var ID = document.customElementID;
/*
this element does not exist during the constructor function so
create your constructor inside a delayed function so that you
can refer to this element instead of just the shadow
*/
setTimeout(function(){
//create a variable to refer to this actual element
var This = document.getElementsByTagName("custom-element-tag")[ID];
},1);
//refer to this's parent
console.log(This.parent);
}//constructor