我在WordPress的職位列表中的這個樣子的:jQuery的分組按首字母
<div class="products uk-grid uk-grid-width-medium-1-4">
<a href="#custom-url"><h3>AShape(14)</h3></a>
<a href="#custom-url"><h3>AShape(20)</h3></a>
<a href="#custom-url"><h3>CShape(38)</h3></a>
<a href="#custom-url"><h3>FShape(1)</h3></a>
<a href="#custom-url"><h3>FShape(4)</h3></a>
<a href="#custom-url"><h3>ZShape(2)</h3></a>
<a href="#custom-url"><h3>ZShape(24)</h3></a>
</div>
我需要找到一些方法來通過腳本的所有鏈接,並在信集團改造它。因此,應採取的首字母從鏈接所有<h3>
,使組像這樣:
<div class="products uk-grid uk-grid-width-medium-1-4">
<div>
<span>A</span>
<a href="#custom-url"><h3>AShape(14)</h3></a>
<a href="#custom-url"><h3>AShape(20)</h3></a>
</div>
<div>
<span>C</span>
<a href="#custom-url"><h3>CShape(38)</h3></a>
</div>
<div>
<span>F</span>
<a href="#custom-url"><h3>FShape(1)</h3></a>
<a href="#custom-url"><h3>FShape(4)</h3></a>
</div>
<div>
<span>Z</span>
<a href="#custom-url"><h3>ZShape(2)</h3></a>
<a href="#custom-url"><h3>ZShape(24)</h3></a>
</div>
</div>
如何,我可以使用jQuery做呢? 這裏我有簡單的codepen:http://codepen.io/ponciusz/pen/EPgQKP
隨機附帶說明,我建議將錨元素放在'h3'元素中.. –