<!DOCTYPE html>
<html>
<head>
<script src="https://code.jquery.com/jquery-3.1.1.min.js" integrity="sha256-hVVnYaiADRTO2PzUGmuLJr8BLUSjGIZsDYGmIJLv2b8=" crossorigin="anonymous"></script>
</head>
<body>
<li class="als-item">
<!-- somefunc1 prints undefined -->
<button onclick="somefunc1(this)" id="mybutton" data-loc-subject="test value">Returns undefined</button>
<!-- somefunc2 prints the data stored in loc-subject -->
<button onclick="somefunc2()" id="mybutton" data-loc-subject="test value">Gets the data</button>
</li>
<script>
function somefunc1(button) {
alert($(this).data('loc-subject'));
}
function somefunc2() {
alert($('#mybutton').data('loc-subject'));
}
</script>
</body>
</html>