What do I need to change in my code?
Each element with the class “date_entry” should have a different attribute set, but currently all elements with that class are getting the same attribute…
$("document").ready(function() {
$(".date_entry").each(function() {
if ($(".date_entry").attr("date", "")) {
var date = $(this).text();
var splitDate = date.split('/');
var year = splitDate[2];
var month = splitDate[0];
var day = splitDate[1];
var newAttr = year + month + day;
$(".date_entry").attr("date", newAttr);
}
});
});
Use the “this” variable: