Essentially, my goal is to extract the selector string from an HTML element. Specifically, I want to start with the HTML element and retrieve its selector string (for example: button#myButton
)
function onclicked(e){
console.log(e.target); // This returns the node HTML element
}
https://i.sstatic.net/Q4WLT.png
If I am unaware of the id or element beforehand, and only discover it upon clicking.
I am looking to obtain the selector string from e.target
that matches the screenshot.
How can I achieve this?
function onclicked(e){
console.log(e.target);
}
<div>
<div>
<div>
<div>
<button id="myButton" onclick="onclicked(event)">click</button>
</div>
</div>
</div>
</div>