JSFiddle - React, Tailwind, and code Playground

by manoj_admlab

HTML

<p class="bbook">Lorem</p>
  <p class="bref">
     <a class="ref" href="prin.v.ii.ii.html">2:15</a>
     <a class="ref" href="prin.v.i.v.html">3:17-19</a>
     <a class="ref" href="prin.v.v.html">3:19 </a>
  </p>

 <p class="bbook">Ipsum</p>
 <p class="bref">
     <a class="ref" href="sec.vii.xxii.html">10:18</a>
     <a class="ref" href="sec.vii.ix.html">10:27</a>
     <a class="ref" href="sec.vii.xxiii.html">10:28</a>
 </p>

JavaScript

$(document).ready(function() {
    var O = {}, el, key, a;
    $('.bbook').each(function(index, value) {
        el = $(value);
        key = el.text();
        O[key] = {};
        el.next().find('a').each(function(i, v) {
            a = $(v);
            O[key][a.attr('href')] = a.text();
        });
    });
    
    console.log(JSON.stringify(O));
});