Your code runs before the .load()
function can return anything. It runs asynchronously to stop blocking other code from running. You can feed a callback function to the load function which will be called when the load function returns. Then the DOM will be updated to know your nav elements.
You can encapsulate your other code in a function and just put that function name as an argument or you can pass an anonymous function and just put all the stuff in there on the spot.
Example:
$('#nav-placeholder').load('assets/nav.html', function() {
const ham = document.getElementById('ham');
ham.addEventListener...
...
..
.
});
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…