Combine 2 Functions To Write To An Attribute Array In Jquery Or Javascript
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
Solution 1:
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.
Post a Comment for "Combine 2 Functions To Write To An Attribute Array In Jquery Or Javascript"