javascript - Jquery Using external URIs as IDs for scrolling -
i know basic question. have following structure:
<li id="example.org/element1"></li> <li id="http://example.org/element2"></li> <li id="example"></li>
i trying scroll positions when clicking elements. function scrolls follows:
var target = ... console.log(target); $('html,body').animate({ scrolltop: $('#' + target).offset().top }, 1000);
this working fine id "example", not other universal ids containing uris:
example.org/element1 jquery-2.2.0.min.js:2 uncaught error: syntax error, unrecognized expression: #example.org/element1 http://example.org/element2 jquery-2.2.0.min.js:2 uncaught error: syntax error, unrecognized expression: #http://example.org/element2
i have been researching , tried options such escaping characters , others, nothing worked. there way can use internally such ids?
use data-id, instead of id, because i'm not sure can in id:
<li data-id="example.org/element1">1</li>
and:
$('[data-id="' + target + '"]')
make sure it's escaped in case has single or double quotes in string
Comments
Post a Comment