给出了以下 HTML 结构且无法更改:
<div id="cone" class="team">
<div class="default"></div>
...
<div class="default">
<img src="img.jpg" width="271" height="271" alt="" border="0"> First Text line<br> Second text line (optional)
<img src="img.jpg" width="271" height="271" alt="" border="0"> First Text line<br> Second text line (optional) ...
</div>
</div>
我想使用 jQuery 得到以下结果:
<div id="cone" class="team">
<div class="default"></div>
...
<div class="default">
<img src="img.jpg" width="271" height="271" alt="" border="0">
<div class="desc">
First Text line<br> Second text line (optional)
</div>
<img src="img.jpg" width="271" height="271" alt="" border="0">
<div class="desc">
First Text line<br> Second text line (optional)
</div>
...
</div>
</div>
我努力了:
$(".team img").each(function () {
$(this.nextSibling).wrap('<div class="desc"></div>');
});
但这仅包含第一行:
<img src="fileadmin/dateien/bilder/team/platzhalter_team.jpg" width="271" height="271" alt="" border="0">
<div class="desc">First Text line</div>
<br>
Second text line (optional)
<img>
重要提示:标签后可以有一行、两行,甚至三行文本。