I need to add dayid to all <td>
for example:
<td class=" " data-year="2022" data-month="8" data-event="click" data-handler="selectDay">
<a class="ui-state-default" href="#">22</a>
</td>
would be like
<td class=" " data-year="2022" data-month="8" dayid="22" data-event="click" data-handler="selectDay">
<a class="ui-state-default" href="#">22</a>
</td>
<td class=" " data-year="2022" data-month="8" dayid="23" data-event="click" data-handler="selectDay">
<a class="ui-state-default" href="#">23</a>
</td> ... and so on
is this possible in jquery? I started writing this
$('td')
.filter('[data-year="2022"]')
.filter('[data-month="08"]')
.find('a') // find all Anchors in this filtered result
.attrib('dayid', '');
but don’t think it can work as I don’t want to hardcode the year & month, and can’t get the value of each to set the attribute
2
Answers
You can start from the
a
and assign it’stext()
to the containingtd
This is not exactly what you asked but here is one way to get all the days of the current calendar using the
data-date
attributes the calendar uses.