<html> <head> <script src="http://code.jquery.com/jquery-1.11.1.min.js"></script> </head> <body> <p id="[foo]"></p> <script> $(window["[foo]"]).attr("value", "123") alert(window["[foo]"].getAttribute("value")) </script> </body> </html>