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 combined and then extended to add an attribute in an array rather than a class.
Original Snippets that added value as classes:-
Gets date from div and add as class
jQuery(".publication-date").each(function(i) {
var yr = $(this).text().trim().split('/')[2];
jQuery(this).closest('.publication').addClass(yr);
});
Gets publication name from div and add as class
jQuery(".publication-name").each(function(i) {
var name = $(this).text().trim().replace(/[_\W]+/g, "-");
jQuery(this).closest('.publication').addClass(name); });
My Effort to combine and write into attribute of 'data-filter' where data-filter had any values separated with a comma ie. data-filter"2017, publicationname"
$(".publication-date, .publication-name").each(function(i) {
var yr = $('.publication-date').text().trim().split('/')[2];
var name = $('.publication-name').text().trim().replace(/[_\W]+/g, "-");
value = yr + ',' + name;
$(this).closest('.publication').attr({
"data-filter": value
});
});
All input greatly appreciated.
Thanks in advance
Glennyboy
2017
tag and you'll see that my rudimentary code does wrap, but it's not dynamic and keeps reproducing. Actually it's a linked issue to https://stackoverflow.com/questions/44685217/call-a-function-init-and-when-isotope-finishes-and-then-reset-on-next-run
– glennyboy Jun 22 '17 at 10:02