On my current webpage, I have a gallery of images accompanied by captions.
<img>image1</img>
<div class="caption">IMAGE 1 TITLE: Subtitle</div>
<img>image2</img>
<div class="caption">IMAGE 2 TITLE: Subtitle</div>
I am interested in rearranging the Image Title
and Subtitle
within each caption so that I can style them individually. Each pair is currently divided by a colon :
. Following this modification, the code should display as follows:
<img src="image1">
<div class="caption">
<span class="title">IMAGE 1 TITLE</span>
<span class="subtitle">Subtitle</span>
</div>
<img src="image2">
<div class="caption">
<span class="title">IMAGE 2 TITLE</span>
<span class="subtitle">Subtitle</span>
</div>
Although I cannot directly edit the HTML code, I do have the ability to inject JS code and insert custom CSS (as it is a squarespace website).
I am seeking a script that can effectively separate the text before and after the colon in each caption and then enclose them within respective classes.