Reputation: 19688
I am trying to auto populate a date range of visible elements. The code I have works fine as long as there is only one empty end date that is filled, but I am having difficulty understanding why the clone() method is running twice.
Fiddle is here.
Basically they are jobs, and roles. A job can have many roles, and I guess roles within a parent job could have overlapping start and end times, but is not necessary for this aspect. The Jobs can, and do, overlap start and end times. The code works by looking for the start and end times described within the HTML of the ROLES, and if there is no end time designated, then to populate the roles end time as "CURRENT". Then, to populate the JOB times, it gathers all of the start times in the array start
(var start = []) and all the end times in the array end
(var end = []). It then sorts start
and end
, and takes the first start
index(date) for the beginning of the JOB, and the last index(date) of end
for the JOB's end date. Somehow the issue is in the line $(this).find('>h1').after($('.workexperience time.end[datetime=' + end[end.length-1] + ']').clone());
, as the arrays seem to be correct.
Can you help point me in the right direction of the error in my code?
per nnnnnn:
the query $('.workexperience time.end[datetime=' + end[end.length-1] + ']')
PRIOR TO THE CLONE is:
[ Current , Current ]
[ Sep 2012 ]
[ Current , Current , Current , Current ]
[ Mar 2006 ]
[ Jun 2002 ]
The query end[end.length-1]
of the variable end results in :
2012-11
2012-09
2012-11
2006-03
2002-06
Upvotes: 2
Views: 481
Reputation: 28154
Your $('.workexperience time.end[datetime=' + end[end.length-1] + ']') is collecting all jobs, while if I understand correctly it should only be scoped to the current job:
$(this).find('time.end[datetime=' + end[end.length-1] + ']').clone()
Fiddle: http://jsfiddle.net/jYnZy/14/
Upvotes: 2