Сообщение от De12
|
Спасибо, попробовал, но почему-то не сработало.
|
Все прекрасно работает
<!DOCTYPE html>
<html>
<head>
<title>Untitled</title>
<meta charset="utf-8">
<style type="text/css">
img {
height: 40px;
margin: 8px;
}
.gal {
border: #0000FF 1px solid;
counter-reset: num;
}
.gal img:before {
counter-increment: num;
content: counter(num)' картинка';
}
</style>
</head>
<body>
<div class="content">
<p>
<img src="http://kangax.github.io/compat-table/logo.png">
<img src="http://kangax.github.io/compat-table/logo.png">
<img src="http://kangax.github.io/compat-table/logo.png">
<img src="http://kangax.github.io/compat-table/logo.png">
<img src="http://kangax.github.io/compat-table/logo.png">
<b>test</b>
<img src="http://kangax.github.io/compat-table/logo.png">
<p>
<div>
<img src="http://kangax.github.io/compat-table/logo.png">
<img src="http://kangax.github.io/compat-table/logo.png">
<img src="http://kangax.github.io/compat-table/logo.png">
</div>
<p>
<img src="http://kangax.github.io/compat-table/logo.png">
</p>
<div>
<img src="http://kangax.github.io/compat-table/logo.png">
<img src="http://kangax.github.io/compat-table/logo.png">
<img src="http://kangax.github.io/compat-table/logo.png">
</div>
</div>
<script>
const images = document.querySelectorAll('div.content img');
for (let i = 0; i < images.length; i++) {
const imgf = images[i];
const arri = [imgf];
let img = imgf.nextElementSibling;
while (img?.tagName === 'IMG') {
arri.push(img);
img = img.nextElementSibling;
i++;
}
if (arri.length > 1) {
const gal = document.createElement('div')
gal.className = 'gal';
imgf.parentElement.replaceChild(gal, imgf);
gal.append(...arri)
}
}
</script>
</body>
</html>