This is an extension of original question: jQuery Extract Year from Date and Add Class to Parent
... but I need to extend it so that the 2 existing functions are com
Assuming that, in your HTML, each of your .publication
div
has one .publicaton-date
div
and one publication-name
div
, you can do something on the lines of:
$('.publication').each(function() {
var yr = $(this).find('.publication-date').text().trim().split('/')[2];
var name = $(this).find('.publication-name').text().trim().replace(/[_\W]+/g, "-");
$(this).attr('data-filter', yr + ',' + name);
})
ie: Instead of looping through the .publication-date
and .publication-name
elements, loop through the .publication
elements and find the date and year inside them.