Elements with $ in the id can't be altered in jquery

I've got a generated file and some IDs contain $ characters. JQuery can't work with the element if it has a $ character in it. Anyway to go around this without changing the IDs?

Example: https://jsfiddle.net/duLba02y/

<div id="test">This works.</div>
<div id="te$t">This doesn't</div>
<script>
   $("#test").hide();
   $("#te$t").hide();
</script>

Solution 1:

Since $ is a meta characters, use \\ to escape it.

$("#te\\$t").hide();

Docs

To use any of the meta-characters ( such as !"#$%&'()*+,./:;<=>?@[]^`{|}~ ) as a literal part of a name, it must be escaped with with two backslashes: \\.