The above solution works for me, but it is worth noting that there are advantages to the native method of getting the element by id: that is, document.getElementById ('strin / g') will work here in cases where jQuery ("strin / g") will fail (because jQuery uses a parser parser that parses the "/" without special handling. escaping). To get a wrapped jQuery version of this element:
jQuery(document.getElementById('activities/_terp_count'));
In fact, if you canβt always precisely control what happens with the actual identifier (say, if you are trying to find a page for an element with the identifier of what was specified in the #hash URL), then a) be careful because it it can be dangerous and b) note that jQuery (document.getElementById (window.location.has.replace ("#", ''))); will work much more reliable than jQuery ("#" + window.location.has.replace ("#", '')); because it will not break so easily.
Example:
jQuery(document.getElementById("_=_")) //<--- null, or the actual element, if you have one which said crazy, non-compliant id jQuery("#_=_") //<--Uncaught Error: Syntax error, unrecognized expression:
If you do not want your users to be able to violate your code simply by entering a specific URL parameter or hash, avoid using this case if you can, and if you cannot, use your own identifier element.
source share