I have a selection of time elements:
[ <time class="end" datetime></time> ,
<time class="end" datetime="2011-12">Dec 2011</time> ,
<time class="end" datetime="2010-01">Jan 2010</time> ,
<time class="end" datetime="2009-01">Jan 2009</time> ,
<time class="end" datetime="2006-12">Dec 2006</time> ,
<time class="end" datetime="2006-05">May 2006</time> ]
that can be selected from the jQuery statement :
$('.workexperience .company .position > time.end')
I am trying to fill the end datetime and the InnerHTML if they are blank with the current month and date, but am having difficulty selecting the datetime attribute of the <time> tag.
- How do I check if it the datetime attr is empty? and
- How do I then fill the text?
I have this function to help with getting the current date and putting it in the month year (Month, YYYY) format. and can adjust it to get the number format for the datetime attribute, just dont know how to select them using JQuery.
function getCurrentDate() {
var d = new Date();
var m = new Array(7);
var y = d.getFullYear();
m[0] = "January"; m[1] = "February"; m[2] = "March"; m[3] = "April"; m[4] = "May"; m[5] = "June"; m[6] = "July"; m[7] = "August"; m[8] = "September"; m[9] = "October"; m[10] = "November"; m[11] = "December";
return m[d.getMonth()] + ", " + y;
};`
As always, thank you for your time and help.
Just use the
.attr()method:…or, even better, the
.prop()method: