Im searching for elements with a class of 'some-class' within an element with a specific ID (provided by the variable myID).
For each one of these I need to get the value of the data attribute called 'data-att'.
I then want to create an array of these but add the string custom-class-- to the beginning of each one.
My code below works except that it only generates 1 value. How can I make an array rather than a variable?
// a in the ID of the container to search in for elements with a class of 'some-class'
var myID = '#' + myID;
// Create a varialbe which starts 'custom-class--' and then has the data-att attribute
// of elements for elemts with a class of 'some-class'
var class = 'custom-class--' + $(myID).find('.some-class').attr('data-att');
UPDATE - here is a working codepen: http://codepen.io/anon/pen/reVeja?editors=1111
<a href="#" class="some-class" data-att="data-1">Link</a>
<div id="my-id">
<a href="#" class="some-class" data-att="data-2">Link</a>
<a href="#" class="some-class" data-att="data-3">Link</a>
</div>
<script type="text/javascript">
$(function() {
// a in the ID of the container to search in for elemnts with a class of 'some-class'
var myID = '#' + 'my-id';
// Create a variable which starts 'custom-class--' and then has the data-att attribute
// of elements for elements with a class of 'some-class'
var myClass = 'custom-class--' + $(myID).find('.some-class').attr('data-att');
console.log(myClass);
});
</script>
.eachjQuery method to loop through the collection