It's ofcourse true you could avoid javascript for such a simple task but if you really need to, you can make it more dynamic and with a smoother scroll.
Your data-target can refer to target's id (better) or to target's text if that's what you really want...
<a class="inpagelink" href="#" id="example" data-target="test">Scroll to</a>
if it is an id you are targeting, the target html would be like that
<h1 id="test">some title</h1>
but it could as well be the text you are targeting
<h1>test</test>
How to target, using jQuery:
Target ID
$('.inpagelink').on('click', function(e){
e.preventDefault();
//get the targets position
var $whereto = $('#'+ $(this).attr('data-target'));
var gotopx = parseInt($whereto.offset().top);
//and scroll there, in 1 sec
$('html, body').animate({ scrollTop: gotopx }, 1000);
});
Target text
$('.inpagelink').on('click', function(e){
e.preventDefault();
//get the targets position
var $whereto = $('h1:contains(' + $(this).attr('data-target') + ')');
var gotopx = parseInt($whereto.offset().top);
//and scroll there, in 1 sec
$('html, body').animate({ scrollTop: gotopx }, 1000);
});
:contains
is case sensitive so have that in mind.