'Special Characters in angular.element

My HTML has a div with id="chart_100%views". When I say angular.element("#chart_100%views"), I get the following error

The app gives this error

I am using angularJS 1.5.8. It works when special characters are removed. Is there a way to get around with special characters?



Solution 1:[1]

You may try the Uni-corn( unicode ) for this: id="chart-100&#37views", hope it help !

Solution 2:[2]

Another option is to use the JQuery function escapeSelector()

angular.element("#" + $.escapeSelector("chart_100%views"));

Solution 3:[3]

$("#" + $.escapeSelector("#text"))

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Vương Tuấn Anh
Solution 2 InquisitiveP
Solution 3 Jakub Kurdziel