Home › Forums › CSS › HTML5 data attributes and Jquery problem › Re: HTML5 data attributes and Jquery problem
Basically, you need to iterate over each element with class `hour` and append the `h3` element (I’m stubborn, by using h5 you’d skip 2 levels)
`$(function() {
// select all the hour elements, iterate over them
$(‘.hour’).each(function() {
// set innerhtml of the current hour element to the data-time
// of the current hour element, wrapped in a h3
$(this).html(‘
‘ + $(this).data(‘time’) + ‘
‘);
});
});`
The keyword here is current, that’s what `$(this)` means in this context, the current element of the iteration. Commented your JavaScript for contrast:
`// you set time to the data-time of the first hour element (‘8am’)
var time = $(‘.hour’).data(‘time’);
// not sure what this $(‘
$8am
‘) does
var hour = $(‘
$’+time+’
‘);
// nice for loop, but you’re doing nothing but printing the same
// variables 12 times
for (i=0; i<12; i++) {`
Hope this helps :)
EDIT: Sorry, had to use “ to keep this forum from parsing the html tags :’)