I have already found the problem with my first code, it was a typo with the li closing tag, @alhazen1 spotted it.