I am looking for a way to be able to select an HTML element by its tag, like:
document.querySelector("<div id='myDiv'>hello world</div>")
//instead of: document.querySelector("#myDiv")
However, this code returns an error. The code should return the HTML element.
Does anybody know a way to achieve this? (vanilla JS preferred)