I have the following HTML:
<aside>
<p class="opentime">10 - 16</p>
<p class="clocknote">Hours</p>
</aside>
After the 10 and the 16, I want the following code to be added:
<span>00</span>
so that it look like this:
<aside>
<p class="opentime">10<span>00</span> - 16<span>00</span></p>
<p class="clocknote">Hours</p>
</aside>
The span tag should be inserted after only the p tags with the class opentime.
Is there any PHP code to make this possible?
The actual code which is in the PHP is the following:
<?php $main_r_t = $pages->find('response_times/main/') ?>
<?php $r_t = $pages->find('response_times/times.txt') ?>
<aside>
<p class="opentime"><?php echo $r_t->mo_time_1() ?></p>
<p class="clocknote"><?php echo $main_r_t->clock() ?></p>
<p class="opentime"><?php echo $r_t->mo_time_2() ?></p>
<p class="clocknote"><?php echo $main_r_t->clock() ?></p>
</aside>
And the text file looks like:
mo_time_1: 10 - 12
----
mo_time_2: 13 - 19
----
If you want to do it in pure PHP (I have no idea what the capabilities/limitations of Kirby are), you could do something like this:
$mo_time = $r_t->mo_time_1();
$time = explode(" - ", $mo_time);
echo "<p class='opentime'>" . $time[0] . "<span>:00</span> - " . $time[1] . "<span>:00</span></p>";
This isn't tested and does no error checking... That's up to you :)
Do this
var text = $(".opentime").html();
var splitString = text.split(" ");
var newstr = splitString[0]+"<span>00</span>"+"-"+splitString[1]+"<span>00</span>";
$(".opentime").html(newstr);