So I have a big list of li
tags that have the following:
<li class="square" data-selected= data-square="1"></li>
<li class="square" data-selected= data-square="2"></li>
<li class="square" data-selected= data-square="3"></li>
onClick
I then add an attribute that's in the data-square
to the data-selected
so onClick
my selected element would look like:
<li class="square" data-selected="3" data-square="3"></li>
I have 30 of these li
tags. I basically want to check if any of them have been selected and if so do something.
$('.square').each(function() {
console.log(count);
var attrSquare = $('.square').attr('data-selected');
if (typeof attrSquare !== typeof undefined && attrSquare !== false) {
console.log('test');
} else {
console.log('selected');
}
});
At the moment, i've placed console.logs
in to see if i'm getting into where i'm getting in. However, it just spits out 30 test in the window console. I never get into the selected console.
Anyone know where i'm going wrong?