I am adding custom data attributes to div. Every time child is clicked it will add value to 'data-selected' attribute to parent (if not already exist), for example:
<div class="parent">
<div class="child" title="a"></div>
<div class="child" title="b"></div>
<div class="child" title="something rather"></div>
<div class="child" title="foo"></div>
</div>
var parent = $('.parent')
$(document).on('click', '.child', function(){
var title = $(this).attr('title')
//parent.attr('data-selected', title)
})
I know I can get parent attributes on child click, split them into array and compare values manually if already exist, but I am wondering is there a direct method which can do this?