The square bracket indicates the attribute selector in jQuery. For this reason, you should not use square brackets as part of the identifier.
You can have the same code without parentheses if you must:
<div id="stuff0">
<div id="tag">blah</div>
</div>
<div id="stuff1">
<div id="tag">blah</div>
</div>
var id = "#" + "stuff0";
$(id).append("<p>HI</p>");
If you do not want to change the HTML code, you can use:
var id = "#" + "stuff\\[0\\]";
$(id).append("<p>HI</p>");
which is not very elegant, but does the job ...
source
share