I am new to programming and stack overflow, so please forgive me if I am not formatting my question properly :)
I'm trying to loop through an array containing three spans, and log the 'data-strength' attribute value. I am able to get the individual spans with $el[i], and am also able to get the attribute value with $el.attr('data-strength'). When I combine the two however $el[i].attr('data-strength'), an error is returned. I assume this is a syntax error, but I'd love some guidance.
I've also included the pen link below. Thanks!!!
<div id="container">
<button id="trigger">Click Me</button>
<div id="strength">
<span data-strength="60"></span>
<span data-strength="50"></span>
<span data-strength="40"></span>
</div>
</div>
var $trigger = $("#trigger"),
$el = $("#strength span"),
$counter = $el.length;
$trigger.click(function(){
for(var i = 0; i < $counter; i++){
var $result = $el[i].attr('data-strength');
console.log($result);
}
});