How will I be able to get all the values of data-val by only using class not id? I can only get the first one. I think this can be accomplished by using loop, but I'm not really sure.
/* JS */
var dataValue = $('.test').data('val');
$('#result').append('Result: ' + dataValue);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<!-- HTML -->
<div data-val="1" class="test"></div>
<div data-val="2" class="test"></div>
<div data-val="3" class="test"></div>
<div id="result"></div>
Not a duplicate of Using jQuery to get data attribute values with .each() because I'm not asking HOW to use .each() I'm asking WHAT to use and there is no each() function in the original post.