Assume you have a valid HTML element in DOM. I assumed the following snippets to be the same. let id = "037e3778-e157-4715-bff5-e466230fe7a3" const byId = document.getElementById(id) console.log(byId) // works const bySelectorConcat = document.querySelector("#" + id) console.log(bySelectorConcat) // Uncaught DOMException: Failed to execute 'querySelector' on 'Document': '#037e3778-e157-4715-bff5-e