I've got a list whereby on click of the anchor, i look at the parent li and get the data-brand attribute and store this in an array and upon click of another item add this to the array. I also want to so if you click an item already in the array it is removed.
Is this reasonably straight forward?
HTML
<div class="search-data__filter">
<ul>
<li data-brand="prada">
<a href="#" class="chkbox">Prada</a>
</li>
<li data-brand="oakley">
<a href="#" class="chkbox">Oakley</a>
</li>
<li data-brand="ray-ban">
<a href="#" class="chkbox">Ray-Ban</a>
</li>
<li data-brand="nike">
<a href="#" class="chkbox">Nike</a>
</li>
</ul>
</div>
jQuery so far:
$(document).ready(function (){
checkbox = $(".chkbox");
checkbox.on("click", function(e){
$(this).toggleClass("is-checked");
var ar = $(this).parent("li").map(function () {
return $(this).attr('data-brand');
});
console.log(ar);
e.preventDefault();
});
});
My log is only storing a single data-attribute and I assume it may be because I am essentially only mapping the parent whom is being clicked? Can't workout how I'd expand on this.