Skip to content

Instantly share code, notes, and snippets.

@ocavue
Last active February 15, 2023 17:05
Show Gist options
  • Select an option

  • Save ocavue/ebee9963dbff92b8c223aa7711346be2 to your computer and use it in GitHub Desktop.

Select an option

Save ocavue/ebee9963dbff92b8c223aa7711346be2 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
.list {
counter-reset: my-list-counter;
counter-increment: my-list-counter;
position: relative;
margin-left: 40px;
}
.list+.list {
counter-reset: none;
}
.list::before {
position: absolute;
right: 100%;
content: counter(my-list-counter, decimal) '. ';
}
</style>
<script>
function onButtonClick() {
let c = document.getElementById("id_c")
let d = document.getElementById("id_d")
d.parentElement.removeChild(d)
c.appendChild(d)
}
</script>
</head>
<body>
<button onclick="onButtonClick()">Click me</button>
<div class="list">
<p>A</p>
</div>
<div class="list">
<p>B</p>
</div>
<div class="list" id="id_c">
<p>C</p>
</div>
<div class="list" id="id_d">
<p>D</p>
</div>
<div class="list">
<p>E (this should be 4 after pressing button)</p>
</div>
<div class="list">
<p>F</p>
</div>
<p>Please check <a href="https://gist.github.com/ocavue/ebee9963dbff92b8c223aa7711346be2">https://gist.github.com/ocavue/ebee9963dbff92b8c223aa7711346be2</a> for more details</p>
</body>
</html>
@ocavue
Copy link
Author

ocavue commented Feb 15, 2023

Description

Chrome cannot display the correct CSS counter value after changing the document.

Step to reproduce

  1. Open https://gistpreview.github.io/?ebee9963dbff92b8c223aa7711346be2/index.html, you should see a list like this

    1. A
    2. B
    3. C
    4. D
    5. E
    6. F
    
  2. Click the button

Expected

The div "D" moves as a child of "C", and the counter number for "E" should be 4.

1. A
2. B
3. C
  1. D
4. E
5. F

Actual

When open the webpage with Chrome, the counter number before "E" is 2.

1. A
2. B
3. C
  1. D
2. E
3. F

Safari and Firefox work fine.

Video

chrome-counter-bug.mp4

Environment

  • macOS 13.1
  • Chrome 110.0.5481.100
  • Firefox 109.0.1
  • Safari 16.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment