In the section "Sortable Lists" of the "Manipulating pages" chapter, the first JavaScript code presents a typo, using
document.querySelectorAll('#sorted')) where it should be (as later explained in the same section) document.querySelectorAll('.sorted')).
After changing that typo, the initial example (using onload for the body) does produce sorted lists, which the book emphasises should not have happened still (but only after we use the DOMContentLoaded event).
Due to the fact that it's not always the case that the DOMContentLoaded event occurs before the load one, a possible way to fix this example/section could be to change the typo (using .sorted) but not including the onload attribute for the body element.
In the section "Sortable Lists" of the "Manipulating pages" chapter, the first JavaScript code presents a typo, using
document.querySelectorAll('#sorted'))
where it should be (as later explained in the same section)document.querySelectorAll('.sorted'))
.After changing that typo, the initial example (using
onload
for the body) does produce sorted lists, which the book emphasises should not have happened still (but only after we use theDOMContentLoaded
event).Due to the fact that it's not always the case that the
DOMContentLoaded
event occurs before theload
one, a possible way to fix this example/section could be to change the typo (using.sorted)
but not including theonload
attribute for the body element.