I am working with a list of elements and I want to be able to redirect the focus to a specific element using a URL.
<div id="20"></div>
<div id="21"></div>
<div id="22"></div>
// example url
http://localhost:8080/#21
var current_url = window.location.href;
// Extract the string after #
var id = current_url.substr(current_url.indexOf("#") + 1);
$('#'+ id).css('border', '1px solid rgb(204, 255, 248)');
The above jQuery code selects the element with id 21 based on the URL;
however, if the URL does not contain a #, it results in the following error:
Uncaught Error: Syntax error, unrecognized expression: #http://localhost:8000/admin/dashboard
Could someone please advise me on how to resolve this issue? Thank you.