JSFiddle - React, Tailwind, and code Playground
by ncapito
HTML
<ul>
<li>
<a href="#">
<img />
<h3>Hello</h3>
<p>World</p>
</a>
</li>
<li>
<img />
<h3>Foo</h3>
<p>Bar</p>
</li>
</ul>
JavaScript
// inside a loop over the listitems
var item = $('li')[0];
var containsLinks = item.children.length === 1 && item.children[0].tagName === "A";
// this does not work...
var captionsContent = $( item ).children()
.filter(containsLinks ? "a" : null)
.not("img")
.wrap( "<div class='ui-captions-content'></div>" );
// neither does that
var captionsContent = $( item ).children()[containsLinks ? children : null]()
.not("img")
.wrap( "<div class='ui-captions-content'></div>" );