actually it's a very good habit when posting questions here to include all the relevant information (rendered html, js and css) in the one code block. It saves people having to ask to see other bits and makes it easier to test your code. Once you have your code working you can do what you like with it.
I've never been hugely swayed by the separation of concerns arguments. If you are working on large frameworks with multiple pages depending on the same external files, of course it makes sense. But to create a separate js file for a few lines of code seems unnecessarily dogmatic.