<div id="qwe"></div> <div id="asd"></div> <div id="zxc"></div> <script> var asd = "var asd"; var div = document.getElementsByTagName("div"); alert(eval(div[1].id)); </script>