I am wondering if I can set the attribute value of an HTML object as a string containing the #
character?
The reason I want to do this is because there will be many elements on the page that should scroll to the specified elements, and I want to save the data, which element should be scrolled to? 'as attribute data-scrollto.
So, my JavaScript code will look like this:
function ScrollToElement(lm) { var theTop = lm.offset().top; $("html,body").animate({ scrollTop: theTop }); }
so the html elements will look like this:
<a class='scroller' data-scrollto='p#p-to-scroll'>Click to scroll to p</a>
safely?
And as a side question, why
$(element).data('scrollto');
doesn't work but
$(element).attr('data-scrollto');
works?
source share